Get Data from Stream

This is a common endpoint used to query data from a stream.

Summary

  • Endpoint: /device_data
  • Method: GET
  • Required User Type: None, this works for all users

Body

Note: all tags must be written with their stream, ie "raw.device_id", where "raw" is the stream and "device_id" is the tag

  • device_id - string of user you want to query data from or list of users you want to query data from
    • Required
    • Type: string or list of strings
    • Allowed users:
      • Any devices linked to current tenant
      • Tenant basic user
      • User basic user
      • If super admin/user: can query from any user
  • stream - stream to query data from
    • Required
    • Type: string
  • limit - maximum number of events to query
    • Default: 1000
    • Type: int
  • since - query events that occurred no earlier than this time
    • Default: Beginning of time
    • Type: Date object or ISO-8601 date string
  • until - query events that occurred no later than this time
    • Default: Now
    • Type: Date object or ISO-8601 date string
  • sort_by - part of event to sort by, typically "observed_at"
    • Default: None
    • Type: string
    • Required with use of "sort_direction"
  • sort_direction - either "asc" or "desc"
    • Default: None
    • Type: string
    • Required with use of "sort_by"
  • rule - rules to limit included data in response by tag presence or equality
    • Default: None
    • Type: list of strings
    • You must surround string tag values with quotes, ie ['name = "test name"']
  • xrule - rules to exclude data from response by tag presence or equality
    • Default: None
    • Type: list of strings
    • You must surround string tag values with quotes, ie ['name = "test name"']
  • filters - filters to limit included data in response with more complexity than rules

Response

A successful response will return an array of objects in the "data" tag of the response.

Each of the objects represents a different user (specified by the "device_id" parameter) and contains a "data" tag which is an array of events matching the query. Each event has "event_id", "observed_at", and "event_data" tags.

Example

Request Body:

{
device_id: 'accounts',
stream: 'licensee_accounts',
limit: 1,
since: new Date(Date.now - 1000), // 1 second ago
sort_by: "observed_at",
sort_direction: "desc", // last events first
rule: ['tenant_user = "t_123"', 'amount = 100'],
xrule: ['name'] // exclude events with name tag,
filters: JSON.stringify({'AND':[['licensee_accounts.faculty_string', "CONTAINS", "abc"], ["licensee_accounts.licensee", "CASE_INSENSITIVE_CONTAINS", "animal"]]})
}

Response Data:

[{
"tag": "_full_event_",
"device_id": "accounts",
"data": [{
"event_id": "123",
"observed_at": "2020-01-07T01:06:31.484870+00:00",
"event_data": {
"tenant_user": "t_123",
"amount": 100,
"faculty_string": "abc123",
"licensee": "ANIMALS!"
}]
}]