API Docs

Density API

Notice: Density API v1 has been deprecated. Density API v2 documentation can be found here.

The Density API provides access to real-time and historical foot traffic data for your Density-enabled spaces.

The Density API is built upon REST, returns JSON responses, and supports cross-origin resource sharing. Standard HTTP verbs are used to perform CRUD operations, and the API returns standard HTTP response codes to indicate errors. API versioning is implemented via namespaces. Token authentication is used to authenticate every API request.

Base URL

https://api.density.io/v1

Authentication

All API endpoints are authenticated using your API token, found in the dashboard.

Your token must be included in the Authorization HTTP header, prefixed by the string literal "Bearer" with a single space separating the two strings. Any API call made without the proper Authorization header will return a 403 error.

HTTP Authorization Header

Authorization: Bearer YOUR_API_TOKEN

Errors

Density endpoints use standard HTTP error codes. The response includes any additional information about the error.

Error Codes

400 Bad Request

The request sent to the API is invalid. Additional information will be returned in the response body.

403 Forbidden

The client is not allowed to perform this request. Can be caused by a missing or invalid API token.

404 Not Found

The requested resource does not exist.

409 Conflict

The request conflicts with another request.

Timestamps

All timestamps sent to the API must be formatted as strings according to the ISO 8601 standard for UTC timestamps. The API will return all timestamps in the same UTC format.

Most programming platforms have built-in utilities to convert between local time and UTC.

ISO 8601 UTC Timestamp

2016-05-23T10:00:00.000Z

Pagination

Density endpoints that return multiple results will be paginated to 200 items by default.

For these endpoints the root of the response object will contain the total count of results, the next and previous page URLs, and an array with the current page of results. If all results fit onto a single page, the next and previous page URLs will be null.

Query String Parameters

page
integer
default: 1

If included, the endpoint will return a particular page of data.

page_size
integer
default: 200

If included, the endpoint will return pages of this size. The maximum page size is 1000.

Example Request

$ curl -H "Authorization: Bearer YOUR_API_TOKEN" \
  https://api.density.io/v1/spaces/?page=4&page_size=15

Paginated Response

{
  "count": 89,
  "next": "https://api.density.io/v1/spaces/?page=5&page_size=15",
  "previous": "https://api.density.io/v1/spaces/?page=3&page_size=15",
  "results": [
    …
  ]
}

Spaces and Counts

The Density API provides real-time and historical traffic data. To query this data only a few endpoints are used.

Density uses the term space for a region where entrances and exits are being counted. Every space created in the Density Dashboard is assigned a unique ID, which you can use to query information for a single space. The current count of people in the space(s) will be included.

List Spaces

List all spaces. Each object returned includes the current count for the space. Note that doorways and daily reset times must be queried for each individual space.

GET /spaces/

Query String Parameters

doorway_id

If included, return only spaces associated with this doorway.

Example Request

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1/spaces/

Example Response

{
  "count": 2,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": "spc_452554024357462439",
      "name": "Office",
      "timezone": "America/New_York",
      "current_count": 5,
      "tags": [
        "tech_garden"
      ]
    },
    {
      "id": "spc_439805443284402880",
      "name": "Conference Room",
      "timezone": "America/New_York",
      "current_count": 2,
      "tags": [
        "tech_garden"
      ]
    }
  ]
}

Get Space

Get detailed information about a space. Includes the current count, the daily reset time, and the list of doorways linked to this space.

GET /spaces/:space_id/

Example Request

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1\
/spaces/spc_452554024357462439/

Example Response

{
  "id": "spc_452554024357462439",
  "name": "Office",
  "description": "The whole Office",
  "timezone": "America/New_York",
  "daily_reset": "13:00",
  "current_count": 5,
  "doorways": [
    {
      "doorway_id": "drw_452554070478029236",
      "name": "Office Door",
      "sensor_placement": 1
    }
  ],
  "tags": [
    "tech_garden"
  ]
}

Get Count

Query the real-time or historical count for a space.

GET /spaces/:space_id/count/

Query String Parameters

time
string
default: now

If included, the endpoint will return the historical count at this time. Must be formatted as an ISO 8601 UTC timestamp.

Example Request

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1\
/spaces/spc_452554024357462439/count/\
?time=2016-05-23T10:10:00.000Z

Example Response

{
  "count": 5
}

Events

For more granular foot traffic data, use the /events/ endpoint to query traffic events within a given time period.

List Events

List foot traffic events for a time period. Each event object specifies a timestamp and direction, along with the count change and new count for any affected spaces.

GET /events/

Query String Parameters

* start_time
required | string

The start time for the historical traffic. Must be formatted as an ISO 8601 UTC timestamp.

end_time
string
default: now

The end time for the historical traffic. Must be formatted as an ISO 8601 UTC timestamp.

space_id
string

If present, only query traffic into or out of this space.

doorway_id
string

If present, only query traffic through this doorway.

Example Request

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1\
/events/?start_time=2016-09-19&end_time=2016-09-20

Example Response

{
  "count": 2,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": "evt_456547729913414419",
      "sensor_id": "snr_457234837531526031",
      "doorway_id": "drw_452554070478029236",
      "timestamp": "2016-09-19T15:32:19.409Z",
      "direction": -1,
      "spaces": [
        {
          "space_id": "spc_452554024357462439",
          "count_change": -1,
          "count": 5
        }
      ]
    },
    {
      "id": "evt_456547726805435148",
      "sensor_id": "snr_457234837531526031",
      "doorway_id": "drw_452554070478029236",
      "timestamp": "2016-09-19T15:32:10.148Z",
      "direction": 1,
      "spaces": [
        {
          "space_id": "spc_452554024357462439",
          "count_change": 1,
          "count": 6
        }
      ]
    }
  ]
}

Simulate Event

Simulate a traffic event. Real sensors will automatically create their own events.

POST /events/

Request Body

* sensor_id
required | string

The id of the sensor that registered the event.

* direction
required | 1 or -1

The direction of the traffic event. If the sensor is mounted on the inside of your space, a direction of 1 means an entry and -1 means an exit.

timestamp
string
default: now

The time the event was detected. Must be formatted as an ISO 8601 UTC timestamp.

Example Request

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
    "sensor_id": "snr_457234837531526031",
    "timestamp": "2016-09-19T15:35:00Z",
    "direction": 1
}' \
https://api.density.io/v1/events/

Example Response

{
  "id": "evt_456547715858301685",
  "sensor_id": "snr_457234837531526031",
  "doorway_id": "drw_452554070478029236",
  "timestamp": "2016-09-19T15:35:00",
  "direction": 1,
  "spaces": [
    {
      "space_id": "spc_452554024357462439",
      "count_change": 1,
      "count": 6
    }
  ]
}

Resets

To reset the current count for a space, or to view historical resets, use the /resets/ endpoint. In production, you can configure the daily_reset property on a space to automatically reset its count every day.

List Resets

List resets for a time period. Each reset contains a timestamp, and the new count for the affected space.

GET /resets/

Query String Parameters

* start_time
required | string

The earliest timestamp to include. Should be formatted as an ISO 8601 UTC timestamp.

end_time
string
default: now

The latest timestamp to include. Should be formatted as an ISO 8601 UTC timestamp.

space_id
string

If present, only return resets for this space.

Example Request

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1\
/resets/?start_time=2016-09-19&end_time=2016-09-20

Example Response

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": "rst_14907317516385010788",
      "space_id": "spc_452554024357462439",
      "timestamp": "2016-09-19T08:00:00",
      "count": 0
    }
  ]
}

Reset Count

Reset the count for a space. The count parameter can be used to reset the count to a number other than 0.

POST /resets/

Request Body

* space_id
required | string

The id of the space that should have its count reset.

count
integer
default: 0

Reset the count to this value.

timestamp
string
default: now

The time of the reset. Should be formatted as an ISO 8601 UTC timestamp.

Example Request

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
    "space_id": "spc_452554024357462439",
    "timestamp": "2016-09-19T15:45:00.000Z",
    "count": 7
}' \
https://api.density.io/v1/resets/

Example Response

{
  "id": "rst_456547733038170906",
  "space_id": "spc_452554024357462439",
  "timestamp": "2016-09-19T15:45:00",
  "count": 7
}

Spaces (Advanced)

The Density API can also be used to create and link spaces and doorways. Most integrations will not need to use these endpoints - spaces, doorways, and tags can be managed in the Density Dashboard (coming soon).

A space can be located within, adjacent to, or overlapping another space. For example, the interior of a conference room can be a space. The interior of the entire building can be a space as well. As long as you can put a name to an indoor region with foot traffic, it can be a space.

Spaces can be organized with tags (see below).

Create Space

Add a space to your environment.

POST /spaces/

Request Body

* name
required | string

The name of the space.

description
string

A description of the space.

timezone
string

The timezone of the space.

daily_reset
string

A 24-hour time in the local time zone. If present, the space's count will automatically reset to 0 at this time every day.

Example Request

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
    "name": "Kitchen",
    "description": "Office Kitchen",
    "daily_reset": "14:00"
}' \
https://api.density.io/v1/spaces/

Example Response

{
  "id": "spc_458687913710846960",
  "name": "Kitchen",
  "description": "Office Kitchen",
  "timezone": "America/New_York",
  "daily_reset": "14:00",
  "current_count": 0,
  "doorways": [],
  "tags": []
}

Update Space

Update a space.

PUT /spaces/:space_id/

Request Body

name
string

The name of the space.

description
string

A description of the space.

timezone
string

The timezone of the space. Should be formatted as an ISO 8601 UTC timestamp.

daily_reset
string

A 24-hour time in the local time zone. If present, the space's count will automatically reset to 0 at this time every day.

Example Request

curl -X PUT \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
    "name": "Kitchen (Updated)",
    "daily_reset": "13:00"
}' \
https://api.density.io/v1\
/spaces/spc_458687913710846960/

Example Response

{
  "id": "spc_458687913710846960",
  "name": "Kitchen (Updated)",
  "description": "Office Kitchen",
  "timezone": "America/New_York",
  "daily_reset": "13:00",
  "current_count": 0,
  "doorways": [],
  "tags": []
}

Delete Space

Delete a space from your environment.

Warning: Deleting a space will destroy all historical counts for that space.

DELETE /spaces/:space_id/

Request Body

* name
required | string

The current name of the space. Must be an exact match.

Example Request

curl -X DELETE \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
    "name": "Kitchen (Updated)"
}' \
https://api.density.io/v1\
/spaces/spc_458687913710846960/

Tag Space

Tag a space.

POST /spaces/:space_id/tags/

Request Body

* tag_name
required | string

The tag name. Alphanumeric characters, underscore or minus sign only.

Example Request

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
    "tag_name": "tech_garden"
}' \
https://api.density.io/v1/spaces/spc_458687913710846960/tags/

Example Response

{
  "tag_name": "tech_garden"
}

Untag Space

Untag a space.

DELETE /spaces/:space_id/tags/:tag_name/

Example Request

curl -X DELETE \
-H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1\
/spaces/spc_458687913710846960/tags/tech_garden/

Doorways

Each space has one or more doorways associated with it. Each doorway is an entrance or exit where a Density sensor can be mounted to detect traffic events. A doorway can be associated with more than one space, if an interior doorway separates two spaces or if two spaces overlap.

Active doorways must have a sensor attached - this is done by setting the sensor_id value on the doorway. Every active doorway has exactly one sensor attached to it.

Doorways can be organized with tags (see below).

List Doorways

List all doorways for an account. Note that space associations must be queried for each individual doorway.

GET /doorways/

Query String Parameters

space_id

If included, return only doorways associated with this space.

Example Request

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1/doorways/

Example Response

{
  "count": 2,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": "drw_437303389773103967",
      "sensor_id": "snr_458467949888405826",
      "name": "Conference Room Door",
      "tags": [
        "tech_garden"
      ]
    },
    {
      "id": "drw_452554070478029236",
      "sensor_id": "snr_457234837531526031",
      "name": "Office Door",
      "tags": [
        "tech_garden"
      ]
    }
  ]
}

Create Doorway

Add a new doorway to your environment.

POST /doorways/

Request Body

* name
required | string

A unique name for the doorway.

description
string

A description for the doorway.

sensor_id
string

The id of the sensor attached to this doorway, if any.

Example Request

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
    "name": "Kitchen Door",
    "description": "The doorway to the Kitchen"
}' \
https://api.density.io/v1/doorways/

Example Response

{
  "id": "drw_456547716936237815",
  "sensor_id": null,
  "name": "Kitchen Door",
  "description": "The doorway to the Kitchen",
  "spaces": [],
  "tags": []
}

Get Doorway

Detailed information about a doorway. The spaces array is a summary of the spaces associated with this doorway. Each association in this array also has a sensor_placement used to configure complex environments. The sensor_placement will be 1 if the sensor is mounted on the inside of the space, and -1 if it is mounted on the outside. Note that a sensor should never be mounted outdoors.

GET /doorways/:doorway_id/

Example Request

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1\
/doorways/drw_437303389773103967/

Example Response

{
  "id": "drw_437303389773103967",
  "sensor_id": "snr_458467949888405826",
  "name": "Conference Room Door",
  "description": "The doorway to the Conference Room (inside the Office)",
  "spaces": [
    {
      "space_id": "spc_439805443284402880",
      "name": "Conference Room",
      "sensor_placement": 1
    }
  ],
  "tags": [
    "tech_garden"
  ]
}

Update Doorway

Update a doorway.

PUT /doorways/:doorway_id/

Request Body

name
string

A unique name for the doorway.

description
string

A description for the doorway.

sensor_id
string

The id of the sensor attached to this doorway, if any.

Example Request

curl -X PUT \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
    "name": "Conference Room Door (Updated)"
}' \
https://api.density.io/v1\
/doorways/drw_437303389773103967/

Example Response

{
  "id": "drw_437303389773103967",
  "sensor_id": "snr_458467949888405826",
  "name": "Conference Room Door (Updated)",
  "description": "The doorway to the Conference Room (inside the Office)",
  "spaces": [
    {
      "space_id": "spc_439805443284402880",
      "name": "Conference Room",
      "sensor_placement": 1
    }
  ],
  "tags": [
    "tech_garden"
  ]
}

Delete Doorway

Delete a doorway from your environment.

DELETE /doorways/:doorway_id/

Example Request

curl -X DELETE \
-H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1\
/doorways/drw_437303389773103967/

Tag Doorway

Tag a doorway.

POST /doorways/:doorway_id/tags/

Request Body

* tag_name
required | string

The tag name. Alphanumeric characters, underscore or minus sign only.

Example Request

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
    "tag_name": "tech_garden"
}' \
https://api.density.io/v1\
/doorways/drw_456547716936237815/tags/

Example Response

{
  "tag_name": "tech_garden"
}

Untag Doorway

Untag a doorway.

DELETE /doorways/:doorway_id/tags/:tag_name/

Example Request

curl -X DELETE \
-H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1\
/doorways/drw_456547716936237815/tags/tech_garden/

Tags

A tag is a text slug (alphanumeric, dash, or underscore only) that can be added to any space or doorway. Tags provide an easy mechanism for filtering and organizing spaces and doorways.

To tag or untag a space or doorway, use the endpoints in the space and doorway sections above.

List Tags

Index of all tags for an account.

GET /tags/

Example Request

$ curl -H "Authorization: Bearer YOUR_API_TOKEN" \ 
  https://api.density.io/v1/tags/

Example Response

{
  "count": 1,
  "next": null,
  "previous": null,
  "results": [
    {
      "name": "tech_garden"
    }
  ]
}

Get Tag

List all spaces and doorways for a single tag. Note that additional details must be queried for each individual item.

GET /tags/:tag_name/

Example Request

$ curl -H "Authorization: Bearer YOUR_API_TOKEN" \
  https://api.density.io/v1/tags/tech_garden/

Example Response

{
  "name": "tech_garden",
  "spaces": [
    {
      "space_id": "spc_439805443284402880",
      "name": "Conference Room",
      "current_count": 3
    },
    {
      "space_id": "spc_452554024357462439",
      "name": "Office",
      "current_count": 7
    },
    {
      "space_id": "spc_458687913710846960",
      "name": "Kitchen (Updated)",
      "current_count": 1
    }
  ],
  "doorways": [
    {
      "doorway_id": "drw_437303389773103967",
      "name": "Conference Room Door (Updated)"
    },
    {
      "doorway_id": "drw_452554070478029236",
      "name": "Office Door"
    },
    {
      "doorway_id": "drw_456547716936237815",
      "name": "Kitchen Door"
    }
  ]
}

Sensors

A Density sensor is the physical hardware module that is mounted above a doorway. Each active doorway must have a sensor associated with it. Density sensors will be automatically updated with their current status.

List Sensors

List sensors in your environment.

GET /sensors/

Example Request

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1/sensors/

Example Response

{
  "count": 2,
  "next": null,
  "previous": null,
  "results": [
    {
      "id": "snr_458467949888405826",
      "doorway_id": "drw_437303389773103967",
      "sensor_type": "s5",
      "status": "online"
    },
    {
      "id": "snr_457234837531526031",
      "doorway_id": "drw_452554070478029236",
      "sensor_type": "s5",
      "status": "online"
    }
  ]
}

Get Sensor

View the current status of a sensor.

GET /sensors/:sensor_id/

Example Request

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1\
/sensors/snr_444718732388860910/

Example Response

{
  "id": "snr_444718732388860910",
  "doorway_id": "drw_456547716936237815",
  "sensor_type": "s5",
  "status": "online"
}

Webhooks

A webhook subscription allows you to receive a callback to a specified endpoint on your own server. Density webhooks will be triggered after every event we receive from one of your sensors.

List Webhooks

List webhooks in your environment.

GET /webhooks/

Example Request

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1/webhooks/

Example Response

{
    "count": 1,
    "next": null,
    "previous": null,
    "results": [
      {
        "id": "whk_444755132324774161",
        "endpoint": "https://your-website.com/some-action"
      }
    ]
}

Create Webhook

Add a new webhook to your environment.

POST /webhooks/

Request Body

* endpoint
required | string

The URL to which Density will send event data.

Example Request

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
    "endpoint": "https://your-website.com/some-action"
}' \
https://api.density.io/v1/webhooks/

Example Response

{
    "id": "whk_444755132324774161",
    "endpoint": "https://your-website.com/some-action"
}

Get Webhook

Detailed information about a webhook.

GET /webhooks/:webhook_id/

Example Request

curl -H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1\
/webhooks/whk_444755132324774161/

Example Response

{
  "id": "whk_444755132324774161",
  "endpoint": "https://your-website.com/some-action"
}

Update Webhook

Update a webhook.

PUT /webhooks/:webhook_id/

Request Body

* endpoint
required | string

A new URL for the endpoint.

Example Request

curl -X PUT \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-d '{
    "endpoint": "https://some-website.com/other-endpoint"
}' \
https://api.density.io/v1\
/webhooks/whk_444755132324774161/

Example Response

{
  "id": "whk_444755132324774161",
  "endpoint": "https://some-website.com/other-endpoint"
}

Delete Webhook

Delete a webhook from your environment.

DELETE /webhooks/:webhook_id/

Example Request

curl -X DELETE \
-H "Authorization: Bearer YOUR_API_TOKEN" \
https://api.density.io/v1\
/webhooks/whk_444755132324774161/

Receiving Webhook

When you receive a webhook, the JSON data will resemble that of an event. See the events section for more information on the direction field.

N/A

Example Webhook Data

{
  "space_id": "spc_14459326507202298682",
  "doorway_id": "drw_437303389773103967",
  "direction": 1,
  "count": 32
}