Overview
3VR Appliances and Enterprise Appliances support several APIs which can be accessed using web services. This has two key advantages for those writing client applications:
These APIs can be used by client applications remotely across a network.
Client applications can be written in almost any programming language.
3VR's Web Services APIs are based on standard protocols and formats such as HTTP, XML, REST, and SOAP which are supported in all major programming environments. In addition, the 3VR Web Services SDK contains sample code and support libraries for several popular programming languages.
In total, the 3VR Web Services API is comprised of 4 APIs:
The 3VR REST API gives client programs access to camera information, system settings, health monitoring data, video, images, and more with RESTful HTTP requests
The 3VR External System Activity API (SOAP) is used by client programs to add events to the 3VR system's database. These include bridges to Point of Sale (POS) systems, access control systems and transaction recording systems. The External System Activity API uses a Simple Object Access Protocol (SOAP) binding that lets client applications define event types and metadata types and inject individual events.
The 3VR External Query API lets client programs query for specific events in the set of events recorded by the 3VR system. 3VR provides RESTful access to some of the most common queries, but client programs can also send custom XML-based queries to return only events of interest. Regardless of which method is chosen, events are returned in XML format and use URLs to reference associated images and videos.
The 3VR Live Query API allows client programs to receive a continuous stream of new events matching an XML query. Clients can choose feeds based on the type of event or whether the event has a particular alert associated with it. The Live Query API uses the same XML predicate request as the External Query API, except the appliance will returns a continuous stream of events instead of a fixed set.
Application developers may use one API or a combination of APIs depending on their needs.
What does an Event mean?
3VR's "Searchable Surveillance" model is built around the creation of events. An event represents an action detected by the 3VR system, such as motion observed by a camera or the detection of a specific face. An event consists of two main components:
Event data: pieces of information such as the date, camera number, transaction ID, etc.
Event video: a video clip from the time when the event occurred.
Each event captured by the 3VR system is represented in OpCenter by an event card. Event cards are labeled with the type of event, the date and time the event card was created, and other information about the event.
The simplest event type is a Motion event. Motion events are created when the system detects movement in a camera's field of view. All motion event cards contain the following elements in storyboard view:
Images: each motion event card displays up to three still frames from the event:
Camera number and name: the number and name of the camera that captured the motion event.
Event start time: the time that motion was first detected by the camera.
Event duration: the length of time continuous motion was detected.
In addition to basic video recording, events can be generated by integration with external systems (e.g. transaction, access control, POS, etc.) and analytics plug-ins.
Choosing the Right API
Before embarking on a project using a 3VR API, application developers should carefully review each API's description and sample code to ensure they have selected the correct API(s) for their purposes. The following guidelines apply:
To create events on the 3VR appliance, use the 3VR External System Activity API
To request and obtain events from the 3VR Appliance that match certain criteria (date, camera, event type, etc.) use the 3VR External Query API.
To request and obtain a continuous stream of events matching a query, use the 3VR Live Query API.
To request information about a 3VR Enterprise Appliance, a single appliance, a camera, or to obtain video or images from a particular camera, use the 3VR REST API.
There are two approaches to developing with the 3VR API: you can either work with the API directly using libraries provided in your programming language of choice, or use 3VR's helper code provided for the language in which you are programming. Both approaches are supported, and the approach you choose will depend on your particular circumstances.
Even if you are writing directly to your language's interfaces, you may find it useful to review the helper code. The source code to the helper code is included in the SDK.
What’s in the SDK?
This manual is associated with a Software Development Kit that has useful tools for programming with 3VR Web services. These include specification files, such as XML schemas, WSDL files, library bindings, source code, and samples of real applications built using these APIs. Also included is a copy of the API documentation in PDF form.
Structure of the API Documentation
3VR's API documentation contains sections for each of the individual APIs. All users should read this Overview and the "Getting Started" section, and then proceed to the documentation for their API of choice.
All of the API-specific sections contain information on the format of the request to the appliance and what to expect in return.
The 3VR External System Activity API and the 3VR External Query API also include sample code to demonstrate the format of the XML request predicate. The 3VR External System Activity API currently includes examples in C# and Java. The 3VR External Query API has examples in Java and Python. Contact your 3VR representative if you are interested in writing client code in other languages.
The final section contains reference material on the structure of XML-formatting for use in specifying queries and processing the events returned from queries.
Getting Started
Enabling Web Services
A 3VR VIP Appliance or Enterprise Appliance must have web services enabled in order to accept incoming messages. Enable web services with the following steps:
Launch 3VR System Manager.
In the Configure panel of System Manager, right-click the name of the appliance and select Start Web Services.
A pop up will appear indicating that web services is now running.
Enabling Demand Video Recording
If you plan to create events, set the Enable Demand Video Recording setting to Yes for each camera that will have generic events. This setting will buffer video so it is available for events even if there is not any current motion.
3VR REST API
The 3VR REST API gives client programs access to camera information, system settings, health monitoring data, video, images, and more with HTTP GET requests.
Authentication
The 3VR REST API uses HTTP Basic Authentication and validates against an appliance’s users. This requires an ’Authorization: Basic’ header in the request followed by a base64 encoded user name and password. This request header is case sensitive and must be passed with every request. The format for the user name and password is username:password. As an example, encoding ‘username:password’ to base64 results in ‘dXNlcm5hbWU6cGFzc3dvcmQ=’, and the request header would be the following:
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
The server will also provide the challenge required for browser authentication. To test in a browser, navigate to a route and enter a valid user name and password in the dialog that’s displayed. The browser will then handle the authentication call.
All permissions, password constraints, authentication attempt limits, and inactivity limits for users are respected. If a user does not have access to an appliance, channel, view, etc. that information will not be returned in the response. When authentication fails the server will respond with a 401 HTTP status code and a JSON object in the body that includes the ‘AuthenticateResponse’ and a ‘Message’ describing the error. For example:
{ "AuthenticateResponse": "PasswordIncorrect", "Message": "Invalid user name or password" }
The following table lists the possible responses:
Port
The 3VR REST API runs on port 8080 and uses SSL, so the server can be accessed via:
https://hostaddress:8080
All exchanges are secured using HTTP BASIC authentication. The user names and passwords must match users that have been added to the 3VR system in System Manager.
Sample Request API
This sample displays the structure of a GET request to an appliance using the 3VR REST API.
In this example, we are requesting a list of system settings, but requests for different information may be made by modifying the path of the request URL (shown in bold text in the following example).
import urllib2, sys def auth(hostname,username,password): url = “https://%s:8080/” % (hostname) password _ mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() handler = urllib2.HTTPBasicAuthHandler(password _ mgr) opener = urllib2.build _ opener(handler) urllib2.install _ opener(opener) password _ mgr.add _ password(None, url, username, password) def get _ settings(hostname): url = "https://%s:8080/settings" % (hostname) #url path to request settings try: req = urllib2.urlopen(url) return req.read() except urllib2.HTTPError, e: print "HTTP error: %s" % e.code except Exception, e: print e return "" if _ _ name _ _ == "_ _ main _ _": try: hostname = sys.argv[1] except: print "usage: settingsAPI.py [IP address or hostname]" sys.exit(1) auth(hostname,"techrep","3MeDeee") settingsxml = get _ settings(hostname)
Headers and Responses
The information below will apply to most 3VR REST API routes. 3VR is in the process of unifying and normalizing its API, so the 3VR REST API routes marked with an asterisk (*) are those still in need of updating. For now, their response will be in XML and they will not take the 'Accept' request header, but will do so in the future.
The default response of all routes will be formatted as JSON objects except for the channel image and video routes.; images routes will return an image, see the routes below for more details. The ‘Accept’ request header allows specifying the desired content type to be returned. For example:
Accept: application/xml Accept: application/json
Please note most browsers will include application/xml in the request header by default, so for debugging purposes an accept argument in the query string may be required to request a JSON formatted response. For example, when retrieving the list of appliances in JSON format using a browser, access the following URL:
https://hostaddress:8080/appliances?accept=application/json
3VR REST API Routes
/appliances
https://[IP address or hostname]:[port]/appliances
Options
?regions=true if included, the returned list of appliances will be arranged in regions
Sample XML Response
<ArrayOfApplianceInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <ApplianceInfo> <Id>1</Id> <Name>3VR Enterprise Appliance</Name> <Address>10.100.2.22</Address> <MachineType>EnterpriseServer</MachineType> <TimeZoneKey>Pacific Standard Time</TimeZoneKey> <TimeZoneOffset>480</TimeZoneOffset> <Created>0001-01-01T00:00:00</Created> <Updated>2012-07-26T00:42:04</Updated> <VideoStart>0001-01-01T00:00:00</VideoStart> <SyncDate>2012-07-02T11:00:14</SyncDate> <ObjectType>appliance</ObjectType> </ApplianceInfo> <ApplianceInfo> <Id>2</Id> <Name>Lake Merritt Branch</Name> <Address>10.100.2.202</Address> <MachineType>Integrated</MachineType> <TimeZoneKey>Pacific Standard Time</TimeZoneKey> <TimeZoneOffset>480</TimeZoneOffset> <Created>2011-04-26T18:37:30</Created> <Updated>2012-07-27T08:56:51</Updated> <VideoStart>2011-04-26T18:46:35</VideoStart> <SyncDate>2012-07-27T08:56:51</SyncDate> <ObjectType>appliance</ObjectType> </ApplianceInfo> </ArrayOfApplianceInfo>
Sample JSON Response
[ { Id: 1, Name: "3VR Enterprise Appliance", Address: "10.100.2.22", MachineType: "EnterpriseServer", TimeZoneKey: "Pacific Standard Time", TimeZoneOffset: 480, Created: "/Date(-62135568000000)/", Updated: "/Date(1343549702000)/", VideoStart: "/Date(-62135568000000)/", SyncDate: "/Date(1341252014000)/", ObjectType: "appliance" }, { Id: 2, Name: "Lake Merritt Branch", Address: "10.100.2.202", MachineType: "Integrated", TimeZoneKey: "Pacific Standard Time", TimeZoneOffset: 480, Created: "/Date(1303868250000)/", Updated: "/Date(1343673311000)/", VideoStart: "/Date(1303868795000)/", SyncDate: "/Date(1343673311000)/", ObjectType: "appliance" } ]
/health
https://[IP address or hostname]:[port]/health
Sample XML Response
<?xml version="1.0" ?> <ArrayOfHealthAlertInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <HealthAlertInfo> <DisplayLabel>Camera or Camera Connection Failure</DisplayLabel> <Id>3</Id> <StartTime>2012-06-20T11:24:10</StartTime> <EndTime>2012-07-27T04:03:55</EndTime> <Message>Camera '1. Shipping Room' is not sending video.</Message> </HealthAlertInfo> </ArrayOfHealthAlertInfo>
/enterprisehealth
https://[IP address or hostname]:[port]/enterprisehealth
Sample XML Response
<ArrayOfEnterpriseHealthAlertInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <EnterpriseHealthAlertInfo> <ApplianceId>2</ApplianceId> <ApplianceName>Lake Merritt Branch</ApplianceName> <ApplianceAddress>10.100.2.202</ApplianceAddress> <DisplayLabel>Camera or Camera Connection Failure</DisplayLabel> <Id>6</Id> <StartTime>2012-06-11T22:32:45</StartTime> <EndTime>2012-07-27T15:03:55</EndTime> <TriggerTime>2012-06-11T23:32:45</TriggerTime> <Message>Camera '7. Mercado' is not sending video.</Message> </EnterpriseHealthAlertInfo> <EnterpriseHealthAlertInfo> <ApplianceId>2</ApplianceId> <ApplianceName>Lake Merritt Branch</ApplianceName> <ApplianceAddress>10.100.2.202</ApplianceAddress> <DisplayLabel>Camera or Camera Connection Failure</DisplayLabel> <Id>7</Id> <StartTime>2012-06-11T22:32:45</StartTime> <EndTime>2012-07-27T15:03:55</EndTime> <TriggerTime>2012-06-11T23:32:45</TriggerTime> <Message>Camera '6. Caja' is not sending video.</Message> </EnterpriseHealthAlertInfo> </ArrayOfEnterpriseHealthAlertInfo>
/appliancemetadata*
https://[IP address or hostname]:[port]/appliancemetadata
Sample XML Response
Sample Response XML <InfoCollectionOfMetadataInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Infos> <MetadataInfo> <Guid>d4fd02e5-d035-4d7e-9aa4-2535a561a748</Guid> <Name>Custom Text Field</Name> <Value>Test Value</Value> </MetadataInfo> <MetadataInfo> <Guid>d4fd02e5-d035-4d7e-9aa4-2535a561a748</Guid> <Name>Custom Number Field</Name> <Value>12</Value> </MetadataInfo> </Infos> </InfoCollectionOfMetadataInfo>
/settings*
https://[IP address or hostname]:[port]/settings
Sample XML Response
<InfoCollectionOfSettingDefinitionInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Infos> <SettingDefinitionInfo> <Id>1</Id> <Name>AdminEMail</Name> <Category>Email</Category> <ChannelId>0</ChannelId> </SettingDefinitionInfo> <SettingDefinitionInfo> <Id>2</Id> <Name>AllowLocalCaseManagement</Name> <Category>General</Category> <ChannelId>0</ChannelId> </SettingDefinitionInfo> <SettingDefinitionInfo> <Id>3</Id> <Name>BackupMedia</Name> <Category>General</Category> <ChannelId>0</ChannelId> </SettingDefinitionInfo> </SettingDefinitionInfo> ... </Infos> </InfoCollectionOfSettingDefinitionInfo>
/settingvalue*
https://[IP address or hostname]:[port]/settingvalue
Sample XML Response
<InfoCollectionOfSettingValueInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Infos> <SettingValueInfo> <Id>20</Id> <Value>false</Value> <ComponentId>5</ComponentId> </SettingValueInfo> </Infos> </InfoCollectionOfSettingValueInfo>
/channelinfo*
https://[IP address or hostname]:[port]/channelinfo
<InfoCollectionOfChannelInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Infos> <ChannelInfo> <Name>Street View</Name> <Number>4</Number> <Id>19</Id> <ChannelDriverName>GenericIPCameraDriver</ChannelDriverName> <PtzState>2</PtzState> <IsActive>false</IsActive> <ChannelType>3</ChannelType> </ChannelInfo> <ChannelInfo> <Name>Classroom</Name> <Number>5</Number> <Id>20</Id> <ChannelDriverName>GenericIPCameraDriver</ChannelDriverName> <PtzState>2</PtzState> <IsActive>false</IsActive> <ChannelType>3</ChannelType> </ChannelInfo> ... </Infos> </InfoCollectionOfChannelInfo>
/hosts
https://[IP address or hostname]:[port]/hosts
Sample XML Response
<ArrayOfHostsInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www. w3.org/2001/XMLSchema"> <HostsInfo> <Label>Lake Merritt Branch</Label> <Id>2</Id> </HostsInfo> <HostsInfo> <Label>Mission District Branch</Label> <Id>3</Id> </HostsInfo> </ArrayOfHostsInfo>
/person/*
https://[IP address or hostname]:[port]/person/
Sample XML Response
<?xml version="1.0" encoding="utf-8"?> <ThreeVRDbSync version="7.0" sourceSystem=""> <Persons> <Person primarykey="Id"> <simplefield name="Id" value="1"/> <simplefield name="FirstName" value="John"/> <simplefield name="LastName" value="Smith"/> <simplefield name="LastSeen" value="2013-03-02T21:22:32-05:00"/> <simplefield name="FirstSeen" value="2013-03-02T21:22:32-05:00"/> <simplefield name="UseForAutoMatch" value="false"/> <complexfield name="Group"> <values> <value> <simplefield name="objectName" value="Imported People"/> <simplefield name="Description" value="Imported People"/> <simplefield name="AutoMatchType" value="UsePersonAutoMatchSetting"/> </value> </values> </complexfield> <image format="jpeg" width="303" height="300"> [IMAGE DATA] </image> </Person> <Person primarykey="Id"> <simplefield name="Id" value="2"/> <simplefield name="FirstName" value="Julie"/> <simplefield name="LastName" value="Smith"/> <simplefield name="LastSeen" value="2013-03-02T21:22:33-05:00"/> <simplefield name="FirstSeen" value="2013-03-02T21:22:33-05:00"/> <simplefield name="UseForAutoMatch" value="false"/> <complexfield name="Group"> <values> <value> <simplefield name="objectName" value="Employees"/> <simplefield name="Description" value="Employees"/> <simplefield name="AutoMatchType" value="UsePersonAutoMatchSetting"/> </value> </values> </complexfield> <simplefield name="Employee ID" value="80"/> <simplefield name="Employee Type" value="Full Time"/> <simplefield name="Gender" value="Female"/> <simplefield name="Hair Color" value="Black"/> <image format="jpeg" width="280" height="280"> [IMAGE DATA] </image> </Person> </Persons> </ThreeVRDbSync>
/livevideo
https://[IP address or hostname]:[port]/livevideo
Sample Response
/video
https://[IP address or hostname]:[port]/video/
WILL BE DEPRECATED IN NEXT RELEASE, USE /channels
Returns stored video from the camera with the given camera number and options (start time, end time, length, framerate, and/or resolution). Note: Datetime values are formatted according to the ISO 8601 specification: YYYY-MM-DDTHH:MM:SS For example, 2012-12-05T13:40:27. For more information, see this article from the W3C W3.org: Date and Time Formats.
/event*
https://[IP address or hostname]:[port]/event/
Sample Response
/liveimage
https://[IP address or hostname]:[port]/liveimage/
Sample Response
/channels
https://[IP address or hostname]:[port]/channel