API
Access Data Analytics widgets underlying data via API
For every Data Analytics widget, the underlying data can be queried via a provided REST API. Integration to third-party applications works out fast and easy.
The REST API makes generated event data available to third-party applications, retrieved from your Data Analytics widgets.

API Call

Once you configure a widget, find the item "API call" in the side menu.
The "API Call" option is available for every widget
The provided dialog pop up shows detailed information on how the API request for the generated data of this particular widget looks like. Copy/paste the curl command into a terminal and execute it. You can directly test the call within the dialog, including the response format, by clicking on "Try it out!" which does not require the usage of a terminal.
The specific API request is ready to use.
The provided access token is temporary. For a permanent integration into third-party applications, please request a permanent access token via the Support Portal.

Authentication

We strictly follow the OAuth flow documented by Microsoft. There are several client libraries that you can use.

Integration example

In the GitHub repository below you can find example code that highlights how to integrate the data into your own application. It showcases how to handle the required authentication as well as how to perform queries.
GitHub - hal9000-swarm/analytics-integration-example: Example of integrating the Swarm data analytics API
GitHub

Example Request

Bicycle Counting

You can see a Data Analytics widget for bicycle counting as an example below. The respective type of widget (Traffic Counting) is selected, data is aggregated per day, split by object class and direction, andand we filter for bicycles only.
Example widget for bicycle counting
API Request
The API-Call option shows the respective GET request for this data, as you can see below.
1
https://example.com/cubejs-api/v1/load?query=
2
{
3
"measures":[
4
"CrossingEvents.count"
5
],
6
"dimensions":[
7
"CrossingEvents.classification",
8
"CrossingEvents.direction"
9
],
10
"segments":[],
11
"filters":[
12
{
13
"member":"CrossingEvents.streamId",
14
"operator":"equals",
15
"values":[
16
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
17
]
18
},
19
{
20
"member":"CrossingEvents.classification",
21
"operator":"contains",
22
"values":[
23
"bicycle"
24
]
25
},
26
{
27
"member":"CrossingEvents.lineId",
28
"operator":"equals",
29
"values":[
30
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
31
]
32
}
33
],
34
"timeDimensions":[
35
{
36
"dimension":"CrossingEvents.timestamp",
37
"granularity":"day",
38
"dateRange":"This week"
39
}
40
],
41
"order":{}
42
}
Copied!
API Response (shortened)
1
{
2
"queryType": "regularQuery",
3
"results": [
4
{
5
"query": {...},
6
"data": [
7
{
8
"CrossingEvents.classification": "bicycle",
9
"CrossingEvents.direction": "in",
10
"CrossingEvents.timestamp.day": "2021-11-02T00:00:00.000",
11
"CrossingEvents.timestamp": "2021-11-02T00:00:00.000",
12
"CrossingEvents.count": 235
13
},
14
{
15
"CrossingEvents.classification": "bicycle",
16
"CrossingEvents.direction": "out",
17
"CrossingEvents.timestamp.day": "2021-11-02T00:00:00.000",
18
"CrossingEvents.timestamp": "2021-11-02T00:00:00.000",
19
"CrossingEvents.count": 234
20
},
21
{
22
"CrossingEvents.classification": "bicycle",
23
"CrossingEvents.direction": "in",
24
"CrossingEvents.timestamp.day": "2021-11-03T00:00:00.000",
25
"CrossingEvents.timestamp": "2021-11-03T00:00:00.000",
26
"CrossingEvents.count": 203
27
},
28
{
29
"CrossingEvents.classification": "bicycle",
30
"CrossingEvents.direction": "out",
31
"CrossingEvents.timestamp.day": "2021-11-03T00:00:00.000",
32
"CrossingEvents.timestamp": "2021-11-03T00:00:00.000",
33
"CrossingEvents.count": 249
34
}
35
],
36
"annotation": {...}
37
}
38
],
39
"pivotQuery": {...}
40
}
Copied!

Extended Documentation

The REST API is based on Cube.js. More information on the functionality of the API can be found in the external documentation.