Camlytics user guide

Overview of Camlytics Camera Software, and how to get started with it.

This section is made for developers or integrators who would like to integrate with Camlytics application.

The REST API allows handling analytical events such as motion detected, camera obstructed, etc. in a custom way. For example, you might want to store events in a remote database, send them to a web service or start an external application.
The API also allows you to receive the list of Camlytics channels with complete details - streaming URI, name, etc. This might be helpful if you plan to use your own player to view cameras remotely (via mobile device).

Camlytics provides a very simple and universal way to control all camera events and retrieve channels data. In order to integrate with the application via REST API, complete the following steps:

  • Start the application and make sure you have the latest version (min supported version is 1.2.0)
  • Enable REST API in settings (it is enabled by default).
  • To verify that the REST API is working, add a channel, generate any event (object appear, etc.) and go to http://localhost:48462/v1/json/events?limit=10&order=DESC&timeout=5. If no events are available, an empty JSON array will be returned.
    In case something went wrong, please refer to logs that are located in %APPDATA%\Camlytics\Logs\.
  • For detailed ducumentation, go through autogenerated REST API reference

For additional support contact us at info@camlytics.com

Please find an example that demonstrates how to integrate with Camlytics REST API using JavaScript.

Also here is a great client implementation by our user on GitHub: https://github.com/turt2live/people-counter

Note that you can use whatever programming language and framework you prefer. The necessary client code can be generated from Swagger definition file which is compliant with Swagger specifications. Please read more about Swagger here.
Online code generation available at SwaggerHub.

If you don't want to write any code to customize events actions locally you can set up the webhook URL for each of the event types. All webhooks are fired via GET requests each time the event is created with following parameters appended: event-type, event-objectId, event-ruleId, event-origin, event-channelId, event-channelName, event-time, event-ruleName.

video camera webhook

A very good example of utilizing webhooks is using Google Sheets as a cloud storage for your Camlytics events - you can use those to collect data from multiple locations, build customized charts, etc.

To automate submission of data into your Google Sheet, fill in the columns headers with parameter names (event-type, event-objectId, etc.) and click Tools > Script editor. You will be redirected to a Google Script page. Copy and paste the sample script below into the script editor.

You can get more information on how to set up the script here.

function doGet(e){
  return handleResponse(e);
}
// Usage
//  1. Enter sheet name where data is to be written below
        var SHEET_NAME = "Sheet1";
//  2. Run > setup
//
//  3. Publish > Deploy as web app 
//    - enter Project Version name and click 'Save New Version' 
//    - set security level and enable service (most likely execute as 'me' and access 'anyone, even anonymously) 
//
//  4. Copy the 'Current web app URL' and post this in your Camlytics webhook URL field
//
//  5. Insert column names on your destination sheet matching the parameter names of the data you are passing in (exactly matching case)
//
var SCRIPT_PROP = PropertiesService.getScriptProperties();
//
function handleResponse(e) {
  var lock = LockService.getPublicLock();
  lock.waitLock(1000);
  
  try {
    var doc = SpreadsheetApp.openById(SCRIPT_PROP.getProperty("key"));
    var sheet = doc.getSheetByName(SHEET_NAME);
    var headRow = 1;
    var headers = sheet.getRange(1, 1, 1, sheet.getLastColumn()).getValues()[0];
    var nextRow = sheet.getLastRow() + 1;
    var row = []; 
    for (i in headers) {
        row.push(decodeURIComponent(e.parameter[headers[i]]));
    }
    sheet.getRange(nextRow, 1, 1, row.length).setValues([row]);
    return ContentService
          .createTextOutput(JSON.stringify({"result":"success", "row": nextRow}))
          .setMimeType(ContentService.MimeType.JSON);
  } catch(e){
    return ContentService
          .createTextOutput(JSON.stringify({"result":"error", "error": e}))
          .setMimeType(ContentService.MimeType.JSON);
  } finally {
    lock.releaseLock();
  }
}
//
function setup() {
    var doc = SpreadsheetApp.getActiveSpreadsheet();
    SCRIPT_PROP.setProperty("key", doc.getId());
}					

In the end you will receive the production script URL that you will insert into your Camlytics events setings in this format: https://script.google.com/macros/s/aKfycbwRo7V-DNXQSCjplDs-j43Y7evXioFNvy_bQs-NNnofPJ41bA52c67/exec
The final URL that webhook is going to build and query is: https://script.google.com/macros/s/aKfycbwRo7V-DNXQSCjplDs-j43Y7evXioFNvy_bQs-NNnofPJ41bA52c67/exec/?event-type=MotionInRegionOn&event-objectId=-1&event-ruleId=06f8590a-10a4-4145-8e8e-5fa7936871bc&event-ruleName=Zone%201&event-origin=Vehicle&event-channelId=395f1e40-7e46-4337-8a7d-5dee549ceb62&event-channelName=Webcam1&event-time=2018-12-21T23%3A50%3A16.1777883%2B03%3A00

Example of output in the Google Sheet that you are going to receive:

camlytics google sheet