Advanced Configurations
Data Connectors can through configuration be tailored to fit more custom use-cases.

Preliminaries

Before diving into how to configure a Data Connector, there are a few things worth keeping in mind when working with them.
    Multiple Projects Data Connectors are created and configured on a per-project basis. If you want multiple projects to send data to the same Endpoint URL, you have to create one Data Connector per project.
    Access Control To create, update, and delete a Data Connector, your DT Studio User or Service Account must have the role of Project Developer or higher.
    Multiple Data Connectors All Data Connectors in a project will receive events from all the devices in that project. It is recommended to filter to event types when possible.

Enable and Disable

It is possible to enabled and disable a Data Connector at will.
DT Studio
REST API
Python API
In DT Studio, click on API Integrations -> Data Connectors. Select the desired Data Connector, then toggle the Data Connector enabled switch. Remember to click Update Data Connector.
Send a PATCH request to:
https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>
A request body with the following parameter should be included.
1
{
2
"status": "ACTIVE"
3
}
Copied!
The status field takes either "ACTIVE" or "USER_DISABLED".

Example Usage

Using cURL with a Service Account for authentication, the following example disables the speficied Data Connector by setting status to "USER_DISABLED".
1
curl -X PATCH "https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>" \
2
-u "<SERVICE_ACCOUNT_KEY_ID>":"<SERVICE_ACCOUNT_SECRET>" \
3
-d '{"status": "USER_DISABLED"}'
Copied!
Once the package is installed and authenticated as described in the Python API Reference, a Data Connector can be updated by calling the following resource method.

Example Usage

Using our Python API with Service Account credentials for authentication, the following example disables the specified Data Connector by setting status to "USER_DISABLED".
1
import disruptive as dt
2
3
# Authenticate the package using Service Account credentials.
4
dt.default_auth = dt.Auth.service_account(
5
key_id='<SERVICE_ACCOUNT_KEY_ID>',
6
secret='<SERVICE_ACCOUNT_SECRET>',
7
email='<SERVICE_ACCOUNT_EMAIL>',
8
)
9
10
# Disabled Data Connector by updating the status.
11
dcon = dt.DataConnector.update_data_connector(
12
data_connector_id='<DATA_CONNECTOR_ID>',
13
project_id='<PROJECT_ID>',
14
status='USER_DISABLED',
15
)
16
17
# Print the updated Data Connector.
18
print(dcon)
Copied!
Disabled Data Connectors have no at-least-once guarantee.
When a Data Connector is disabled, undelivered events and events generated after being disabled will not be sent. Re-enabling the Data Connector will not backfill data from the period it was disabled and must be fetched programmatically using our REST API.

Auto-Disabled Data Connectors

A Data Connector will be automatically disabled by DT Cloud if it has failed for an extended period of time without any success. A push-attempt from a Data Connector is considered a failure if the receiver responded with a non-200 status code, or didn’t respond at all. A Data Connector that is disabled by DT Cloud will get the status SYSTEM_DISABLED.

Filtering on Event Types

By default, all event types are forwarded by a Data Connector. If you want to avoid uneccesary traffic on your endpoint, events can be filtered by type.
DT Studio
REST API
Python API
In DT Studio, click on API Integrations -> Data Connectors. Select the desired Data Connector, then toggle the Forward All Events followed by a selection. Remember to click Update Data Connector.
Send a PATCH request to:
https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>
A request body with the following parameter should be included.
1
{
2
"events": ["touch", "temperature", ...]
3
}
Copied!
The events array takes one- or several event types.

Example Usage

Using cURL with a Service Account for authentication, the following example sets a filter so that only temperature- and humidity events are forwarded.
1
curl -X PATCH "https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>" \
2
-u "<SERVICE_ACCOUNT_KEY_ID>":"<SERVICE_ACCOUNT_SECRET>" \
3
-d '{"events": ["temperature", "humidity"]}'
Copied!
Once the package is installed and authenticated as described in the Python API Reference, a Data Connector can be updated by calling the following resource method.

Example Usage

Using our Python API with Service Account credentials for authentication, the following example sets a filter so that only temperature- and humidity events are forwarded.
1
import disruptive as dt
2
3
# Authenticate the package using Service Account credentials.
4
dt.default_auth = dt.Auth.service_account(
5
key_id='<SERVICE_ACCOUNT_KEY_ID>',
6
secret='<SERVICE_ACCOUNT_SECRET>',
7
email='<SERVICE_ACCOUNT_EMAIL>',
8
)
9
10
# Update the Data Connector to only forward specified events.
11
dt.DataConnector.update_data_connector(
12
data_connector_id='<DATA_CONNECTOR_ID>',
13
project_id='<PROJECT_ID>',
14
event_types=[
15
dt.events.TEMPERATURE,
16
dt.events.HUMIDITY,
17
],
18
)
Copied!

Including Labels

You can include labels held by a device with each event forwarded by the Data Connector.
DT Studio
REST API
Python API
In DT Studio, click on API Integrations -> Data Connectors. Select the desired Data Connector, then append the label keys to the list. Remember to click Update Data Connector.
Send a PATCH request to:
https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>
A request body with the following parameter should be included.
1
{
2
"labels": ["label-01", "label-02", ...]
3
}
Copied!

Example Usage

Using cURL with a Service Account for authentication, the following example configures the specified Data Connector to include device labels called "floor" and "customer-ID".
1
curl -X PATCH "https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>" \
2
-u "<SERVICE_ACCOUNT_KEY_ID>":"<SERVICE_ACCOUNT_SECRET>" \
3
-d '{"labels": ["floor", "customer-ID"]}'
Copied!
Once the package is installed and authenticated as described in the Python API Reference, a Data Connector can be updated by calling the following resource method.

Example Usage

Using our Python API with Service Account credentials for authentication, the following example configured a Data Connector to include device labels called "floor" and "customer-ID".
1
import disruptive as dt
2
3
# Authenticate the package using Service Account credentials.
4
dt.default_auth = dt.Auth.service_account(
5
key_id='<SERVICE_ACCOUNT_KEY_ID>',
6
secret='<SERVICE_ACCOUNT_SECRET>',
7
email='<SERVICE_ACCOUNT_EMAIL>',
8
)
9
10
# Update the Data Connector to include device labels.
11
dt.DataConnector.update_data_connector(
12
data_connector_id='<DATA_CONNECTOR_ID>',
13
project_id='<PROJECT_ID>',
14
labels=['floor', 'customer-ID'],
15
)
Copied!

DT Studio Specific Labels

DT Studio uses labels with the keys name and description to show as the display name and the description of a device. It is recommended that an integration uses these labels in the same way when displaying or updating a device.

Adding HTTP Headers

Custom HTTP headers can be included with each event forwarded by a Data Connector.
DT Studio
REST API
Python API
In DT Studio, click on API Integrations -> Data Connectors. Select the desired Data Connector, then add a key- and value pairs for your custom headers. Remember to click Update Data Connector.
Send a PATCH request to:
https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>
A request body with the following parameter should be included.
1
{
2
"httpConfig": {
3
"headers": {
4
"name-1": "value-1",
5
"name-2": "value-2",
6
...
7
}
8
}
9
}
Copied!

Example Usage

Using cURL with a Service Account for authentication, the following example adds the header "my-header" with value "my-value" to every event forwarded by a Data Connector.
1
curl -X PATCH "https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>" \
2
-u "<SERVICE_ACCOUNT_KEY_ID>":"<SERVICE_ACCOUNT_SECRET>" \
3
-d '{"httpConfig": {"headers": {"my-header": "my-value"}}}'
Copied!
Once the package is installed and authenticated as described in the Python API Reference, a Data Connector can be updated by calling the following resource method.

Example Usage

Using our Python API with Service Account credentials for authentication, the following example adds the header "my-header" with value "my-value" to every forwarded event.
1
import disruptive as dt
2
3
# Authenticate the package using Service Account credentials.
4
dt.default_auth = dt.Auth.service_account(
5
key_id='<SERVICE_ACCOUNT_KEY_ID>',
6
secret='<SERVICE_ACCOUNT_SECRET>',
7
email='<SERVICE_ACCOUNT_EMAIL>',
8
)
9
10
# Update the Data Connector to include custom HTTP headers.
11
dt.DataConnector.update_data_connector(
12
data_connector_id='<DATA_CONNECTOR_ID>',
13
project_id='<PROJECT_ID>',
14
config=dt.DataConnector.HttpPushConfig(
15
headers={
16
'my-header': 'my-value',
17
},
18
),
19
)
Copied!

Signing Events

For increased security in a production integration, we recommend signing each Event with a Signature Secret that can be verified on the receiving end.
    The HTTP header includes a JSON Web Token (JWT) signed with the Signature Secret.
    The JWT payload contains the checksum of the request body.
This allows you to both validate the origin and content integrity of the received request for a more secure connection. The process is two-fold and must be configured for both the Data Connector and endpoint.

Signing Events Sent by the Data Connector

Adding a signature secret to your Data Connector will automatically sign each forwarded event.
DT Studio
REST API
Python API
In DT Studio, click on API Integrations -> Data Connectors. Select the desired Data Connector, then add a strong and unique signature secret. Remember to click Update Data Connector.
Send a PATCH request to:
https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>
A request body with the following parameter should be included.
1
{
2
"httpConfig": {
3
"signatureSecret": "some-good-secret"
4
}
5
}
Copied!

Example Usage

Using cURL with a Service Account for authentication, the following example adds a signature secret to the specified Data Connector.
1
curl -X PATCH "https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>" \
2
-u "<SERVICE_ACCOUNT_KEY_ID>":"<SERVICE_ACCOUNT_SECRET>" \
3
-d '{"httpConfig": {"signatureSecret": "some-good-secret"}}
Copied!
Once the package is installed and authenticated as described in the Python API Reference, a Data Connector can be updated by calling the following resource method.

Example Usage

Using our Python API with Service Account credentials for authentication, the following example adds a signature secret to the specified Data Connector.
1
import disruptive as dt
2
3
# Authenticate the package using Service Account credentials.
4
dt.default_auth = dt.Auth.service_account(
5
key_id='<SERVICE_ACCOUNT_KEY_ID>',
6
secret='<SERVICE_ACCOUNT_SECRET>',
7
email='<SERVICE_ACCOUNT_EMAIL>',
8
)
9
10
# Update the Data Connector with a signature secret.
11
dt.DataConnector.update_data_connector(
12
data_connector_id='<DATA_CONNECTOR_ID>',
13
project_id='<PROJECT_ID>',
14
config=dt.DataConnector.HttpPushConfig(
15
signature_secret='some-good-secret',
16
),
17
)
Copied!

Verifying Signed Events

To handle incoming events that have been signed by a signature secret, see Verifying Signed Events.

Synchronize

When synchronizing the Data Connector, the state of each device currently in the project will be sent as events. These events will be dated back in time to when they were reported from the device. Note, however, that the event id will be different for the synchronized events.
DT Studio
REST API
Python API
In DT Studio, click on API Integrations -> Data Connectors. Select the desired Data Connector, then click Synchronize Data Connector towards the bottom of the page.
Send a POST request to:
https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR>:sync

Example Usage

Using cURL with a Service Account for authentication, the following example syncs the specified Data Connector.
1
curl -X POST "https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>:sync" \
2
-u "<SERVICE_ACCOUNT_KEY_ID>":"<SERVICE_ACCOUNT_SECRET>"
Copied!
Once the package is installed and authenticated as described in the Python API Reference, a Data Connector can be synced by calling the following resource method.

Example Usage

Using our Python API with Service Account credentials for authentication, the following example syncs the specified Data Connector.
1
import disruptive as dt
2
3
# Authenticate the package using Service Account credentials.
4
dt.default_auth = dt.Auth.service_account(
5
key_id='<SERVICE_ACCOUNT_KEY_ID>',
6
secret='<SERVICE_ACCOUNT_SECRET>',
7
email='<SERVICE_ACCOUNT_EMAIL>',
8
)
9
10
# Sync the specified Data Connector.
11
dt.DataConnector.sync_data_connector(
12
data_connector_id='<DATA_CONNECTOR_ID>',
13
project_id='<PROJECT_ID>',
14
)
Copied!
Last modified 1mo ago