Using GraphQL

In this tutorial we will show you how you can use the powerful GraphQL API to access historical and current device data with Datacake.

GraphQL Requests

HTTP

You can use a cURL Command to call the GraphQL Library directly.

curl \
-X GET \
-H "Content-Type: application/json" \
-H "Authorization: Token 1234567yourtoken1234567" \
--data '{"query": "query { allDevices(inWorkspace:\"dc578994-your-workspace-84221d0\") { currentMeasurements(allActiveFields: true) { value field { verboseFieldName fieldName } } } }"}' \
https://api.datacake.co/graphql/

Libraries

Datacake Python Wrapper

Datacake official Python GraphQL wrapper:

iOS

You can use the Apollo GraphQL Library in your iOS / Swift Applications:

Node-RED

You can use a function node in Node-RED and create a custom GraphlQL query that forwards data directly into Node-RED as a parsed JSON-Object.

Node-RED Flow Export

Copy the following Node-RED Flow of a working Datacake GraphQL Example and paste this into your Node-RED using "Import" function.

Workspaces

List of Workspaces

List of Devices

Current Measurements

All Devices in Workspace

You can use the currentMeasurements option to have all the last recorded measurements of one or more devices returned.

Use the allActiveFields option as follows to return only those fields that are active in the database.

Specific Fields only

Single Fields only

Instead of providing an Array of Field Identifiers you can use the currentMeasurement Option to Query a specific field only.

Specific Device

The above examples are using the allDevices Option to query all devices in a given Workspace. If you just want to access data from a specific device only, you can use the device Option.

Use this as in the following example query:

Working with Strings

If your fields in database store a String-type value you have to add the valueString option to return the corresponding value.

Working with Maximum, Average

So will look like

Historical Data

From all Devices in Workspace

  • fields: Set of fields, has to be identifier of database field.

  • timerangestart: Starting of time frame, has to be before timerangeend.

  • timerangeend: End of time frame, should never be in the future.

  • resultion: Quantisation-Factor, see below.

From a Specific Device

Fields have to be Identifier:

Multiple Fields

Working with Resolution

One of the options for the history settings is an option called resolution. This gives you two options:

  • raw - Raw Data Export. Data will be exported as stored in the database

  • X minutes - Quantisation in X Minutes - Data will be combined into timerange-chunks of given value.

  • Other valid values are: X hours

The operation for quantisation is an average. You cannot change this right now.

Raw Data Export

Quantisation

Devices

Metadata

The following snippet works for both allDevices and specific device Options.

Last updated

Was this helpful?