Skip to main content

Data Actions

https://api.losant.com/applications/APPLICATION_ID/data

Below are the various requests that can be performed against the Data resource, as well as the expected parameters and the potential responses.

Export​

Creates a csv file from a query of devices and attributes over a time range.

Method And Url​

POST https://api.losant.com/applications/APPLICATION_ID/data/export

Authentication​

A valid API access token is required to access this endpoint. The token must include at least one of the following scopes: all.Application, all.Application.bounded, all.Application.read, all.Device, all.Device.read, all.Organization, all.Organization.bounded, all.Organization.read, all.User, all.User.bounded, all.User.read, data.*, or data.export.

Request Path Components​

Path ComponentDescriptionExample
APPLICATION_IDID associated with the application575ec8687ae143cd83dc4a97

Request Headers​

NameRequiredDescriptionDefault
AuthorizationYThe token for authenticating the request, prepended with Bearer

Request Body​

The body of the request should be serialized JSON that validates against the Devices Data Export schema. For example, the following would be a valid body for this request:

{
"email": "export@example.com",
"deviceIds": [
"575ecf887ae143cd83dc4aa2",
"575ef5c97ae143cd83dc4aac"
],
"attributes": [
"voltage"
],
"end": 0,
"options": {
"includeDate": false,
"includeID": true
}
}

Curl Example​

curl -H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_API_ACCESS_TOKEN' \
-X POST \
-d '{"email":"export@example.com","deviceIds":["575ecf887ae143cd83dc4aa2","575ef5c97ae143cd83dc4aac"],"attributes":["voltage"],"end":0,"options":{"includeDate":false,"includeID":true}}' \
https://api.losant.com/applications/APPLICATION_ID/data/export

Successful Responses​

CodeTypeDescription
202Job Enqueued API ResultIf command was successfully sent

Error Responses​

CodeTypeDescription
400ErrorError if malformed request
404ErrorError if application was not found

Last Value Query​

Returns the last known data for the given attribute

Method And Url​

POST https://api.losant.com/applications/APPLICATION_ID/data/last-value-query

Authentication​

A valid API access token is required to access this endpoint. The token must include at least one of the following scopes: all.Application, all.Application.bounded, all.Application.read, all.Device, all.Device.read, all.Organization, all.Organization.bounded, all.Organization.read, all.User, all.User.bounded, all.User.read, data.*, or data.lastValueQuery.

Request Path Components​

Path ComponentDescriptionExample
APPLICATION_IDID associated with the application575ec8687ae143cd83dc4a97

Request Headers​

NameRequiredDescriptionDefault
AuthorizationYThe token for authenticating the request, prepended with Bearer

Request Body​

The body of the request should be serialized JSON that validates against the Last Value Query schema. For example, the following would be a valid body for this request:

{
"deviceIds": [
"575ecf887ae143cd83dc4aa2",
"575ef5c97ae143cd83dc4aac"
],
"attribute": "voltage"
}

Curl Example​

curl -H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_API_ACCESS_TOKEN' \
-X POST \
-d '{"deviceIds":["575ecf887ae143cd83dc4aa2","575ef5c97ae143cd83dc4aac"],"attribute":"voltage"}' \
https://api.losant.com/applications/APPLICATION_ID/data/last-value-query

Successful Responses​

CodeTypeDescription
200Last Value DataLast known data for the requested attribute

Error Responses​

CodeTypeDescription
400ErrorError if malformed request
404ErrorError if application was not found

Time Series Query​

Returns the data for the given query

Method And Url​

POST https://api.losant.com/applications/APPLICATION_ID/data/time-series-query

Authentication​

A valid API access token is required to access this endpoint. The token must include at least one of the following scopes: all.Application, all.Application.bounded, all.Application.read, all.Device, all.Device.read, all.Organization, all.Organization.bounded, all.Organization.read, all.User, all.User.bounded, all.User.read, data.*, or data.timeSeriesQuery.

Request Path Components​

Path ComponentDescriptionExample
APPLICATION_IDID associated with the application575ec8687ae143cd83dc4a97

Request Headers​

NameRequiredDescriptionDefault
AuthorizationYThe token for authenticating the request, prepended with Bearer

Request Body​

The body of the request should be serialized JSON that validates against the Time Series Query schema. For example, the following would be a valid body for this request:

{
"end": 0,
"duration": 600000,
"resolution": 300000,
"aggregation": "MEAN",
"attributes": [
"voltage"
],
"deviceTags": [
{
"key": "floor",
"value": "8"
}
]
}

Curl Example​

curl -H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'Authorization: Bearer YOUR_API_ACCESS_TOKEN' \
-X POST \
-d '{"end":0,"duration":600000,"resolution":300000,"aggregation":"MEAN","attributes":["voltage"],"deviceTags":[{"key":"floor","value":"8"}]}' \
https://api.losant.com/applications/APPLICATION_ID/data/time-series-query

Successful Responses​

CodeTypeDescription
200Time Series DataData for requested time range

Error Responses​

CodeTypeDescription
400ErrorError if malformed request
404ErrorError if application was not found

Schemas​

Devices Data Export​

Schema for exporting the data for multiple devices

Devices Data Export Schema​

  • ▶
    {} 4 keys
    • "http://json-schema.org/draft-07/schema#"
    • "object"
    • ▶
      {} 9 keys
      • ▶
        {} 3 keys
        • ▶
          {} 3 keys
          • ▶
            {} 3 keys
            • ▶
              {} 3 keys
              • ▶
                {} 5 keys
                • ▶
                  {} 3 keys
                  • ▶
                    {} 1 key
                    • ▶
                      {} 1 key
                      • ▶
                        {} 2 keys
                      • false

                    Devices Data Export Example​

                    • ▶
                      {} 5 keys
                      • "export@example.com"
                      • ▶
                        [] 2 items
                        • ▶
                          [] 1 item
                          • 0
                          • ▶
                            {} 2 keys

                          Error​

                          Schema for errors returned by the API

                          Error Schema​

                          • ▶
                            {} 3 keys
                            • "http://json-schema.org/draft-07/schema#"
                            • "object"
                            • ▶
                              {} 3 keys
                              • ▶
                                {} 1 key
                                • ▶
                                  {} 1 key
                                  • ▶
                                    {} 2 keys

                                Error Example​

                                • ▶
                                  {} 2 keys
                                  • "NotFound"
                                  • "Application was not found"

                                Job Enqueued API Result​

                                Schema for the result of a job being queued

                                Job Enqueued API Result Schema​

                                • ▶
                                  {} 3 keys
                                  • "http://json-schema.org/draft-07/schema#"
                                  • "object"
                                  • ▶
                                    {} 3 keys
                                    • ▶
                                      {} 2 keys
                                      • ▶
                                        {} 2 keys
                                        • ▶
                                          {} 2 keys

                                      Job Enqueued API Result Example​

                                      • ▶
                                        {} 3 keys
                                        • true
                                        • "clnHvJbyVkOWAZwYAwLP4"
                                        • true

                                      Last Value Data​

                                      Schema for the result of a last value query

                                      Last Value Data Schema​

                                      • ▶
                                        {} 4 keys
                                        • "http://json-schema.org/draft-07/schema#"
                                        • "object"
                                        • ▶
                                          {} 1 key
                                          • false

                                        Last Value Data Example​

                                        • ▶
                                          {} 2 keys
                                          • ▶
                                            {} 2 keys
                                            • ▶
                                              {} 2 keys

                                            Last Value Query​

                                            Schema for the body of a last value query request

                                            Last Value Query Schema​

                                            • ▶
                                              {} 4 keys
                                              • "http://json-schema.org/draft-07/schema#"
                                              • "object"
                                              • ▶
                                                {} 5 keys
                                                • ▶
                                                  {} 2 keys
                                                  • ▶
                                                    {} 3 keys
                                                    • ▶
                                                      {} 3 keys
                                                      • ▶
                                                        {} 5 keys
                                                        • ▶
                                                          {} 1 key
                                                        • false

                                                      Last Value Query Example​

                                                      • ▶
                                                        {} 2 keys
                                                        • ▶
                                                          [] 2 items
                                                          • "voltage"

                                                        Time Series Data​

                                                        Schema for the result of a time series query

                                                        Time Series Data Schema​

                                                        • ▶
                                                          {} 5 keys
                                                          • "http://json-schema.org/draft-07/schema#"
                                                          • "object"
                                                          • ▶
                                                            {} 7 keys
                                                            • ▶
                                                              {} 2 keys
                                                              • ▶
                                                                {} 2 keys
                                                                • ▶
                                                                  {} 1 key
                                                                  • ▶
                                                                    {} 1 key
                                                                    • ▶
                                                                      {} 1 key
                                                                      • ▶
                                                                        {} 2 keys
                                                                        • ▶
                                                                          {} 3 keys
                                                                        • false
                                                                        • ▶
                                                                          [] 7 items

                                                                        Time Series Data Example​

                                                                        • ▶
                                                                          {} 7 keys
                                                                          • "2016-06-15T03:50:00.000Z"
                                                                          • "2016-06-15T04:00:00.000Z"
                                                                          • 300000
                                                                          • "MEAN"
                                                                          • null
                                                                          • "asc"
                                                                          • ▶
                                                                            {} 2 keys

                                                                          Time Series Query​

                                                                          Schema for the body of a time series query request

                                                                          Time Series Query Schema​

                                                                          • ▶
                                                                            {} 4 keys
                                                                            • "http://json-schema.org/draft-07/schema#"
                                                                            • "object"
                                                                            • ▶
                                                                              {} 11 keys
                                                                              • ▶
                                                                                {} 1 key
                                                                                • ▶
                                                                                  {} 1 key
                                                                                  • ▶
                                                                                    {} 1 key
                                                                                    • ▶
                                                                                      {} 1 key
                                                                                      • ▶
                                                                                        {} 1 key
                                                                                        • ▶
                                                                                          {} 2 keys
                                                                                          • ▶
                                                                                            {} 3 keys
                                                                                            • ▶
                                                                                              {} 3 keys
                                                                                              • ▶
                                                                                                {} 5 keys
                                                                                                • ▶
                                                                                                  {} 1 key
                                                                                                  • ▶
                                                                                                    {} 3 keys
                                                                                                  • false

                                                                                                Time Series Query Example​

                                                                                                • ▶
                                                                                                  {} 6 keys
                                                                                                  • 0
                                                                                                  • 600000
                                                                                                  • 300000
                                                                                                  • "MEAN"
                                                                                                  • ▶
                                                                                                    [] 1 item
                                                                                                    • ▶
                                                                                                      [] 1 item

                                                                                                    Was this page helpful?


                                                                                                    Still looking for help? You can also search the Losant Forums or submit your question there.