DT Developer Docs
REST APIDT StudioStatus Page
  • Getting Started
  • Overview
  • Concepts
    • Devices
    • Events
    • Topics
      • Temperature Measurement Interval
      • Motion Sensor Activity Timer
  • Data Connectors
    • Introduction to Data Connectors
    • Creating a Data Connector
    • Configuring a Data Connector
    • Receiving Events
    • Best Practices
    • Example Integrations
      • Heroku
      • Google Cloud Functions
      • AWS Lambda
      • Azure HTTP Triggers
      • IBM Cloud Actions
    • Development Guides
      • Local Development with ngrok
  • REST API
  • Introduction to REST API
  • Explore Our Endpoints
    • with cURL
    • with Python API
    • with Postman
  • Authentication
    • OAuth2
    • Basic Auth
  • Error Codes
  • Emulator API
  • Examples
    • Pagination
    • Streaming Events
    • Touch to Identify
    • Refreshing Access Token
  • Reference
  • Status Page
  • Service Accounts
    • Introduction to Service Accounts
    • Creating a Service Account
    • Managing Access Rights
    • Permissions
    • Organizational Structures
  • Other
    • Application Notes
      • Generating a Room Temperature Heatmap
      • Modeling Fridge Content Temperatures
      • Outlier Detection on Multiple Temperature Sensors
      • Simple Temperature Forecasting for Substation Transformers
      • Sensor Data Insight with Power BI and Azure
      • Third-Party Sensor Data in DT Cloud
    • Frequently Asked Question
Powered by GitBook
On this page
  • Overview
  • Prerequisites
  • Creating a New Data Connector
  • Test Your Data Connector

Was this helpful?

  1. Data Connectors

Creating a Data Connector

A quick guide on how to create a Data Connector using DT Studio or our APIs.

Last updated 9 months ago

Was this helpful?

Overview

To illustrate the process, we will create a new Data Connector that forwards all events to , a free service that fulfills the same role as a server that lets you inspect the contents of each request. If you already have an HTTPS POST endpoint set up, feel free to use that instead.

Prerequisites

  • Service Account Creating, updating, and deleting Data Connectors requires that your User or has been granted the Project Developer or higher.

  • HTTPS Endpoint Data Connectors sends events as POST requests over HTTPS. In order to receive these events you need to have a service up and running that can accept incoming HTTPS connections.HTTP is not supported. In this guide, we will use as an example.

Please note that Disruptive Technologies and webhook.site are in no way affiliated and that the data sent there is publicly available.

Creating a New Data Connector

Data Connectors can be created using either the DT Studio interface or our REST API. For simplicity, most of the configurations will be left as default in this example. If you're interested in a more custom Data Connector, see the page for more information.

In , navigate to your Project. In the left menu, locate Data Connectors under API Integrations and press Add Data Connector. This will open the Data Connector configuration menu.

Edit the following parameters.

  • Display name Give the Data Connector some identifiable display name.

  • Endpoint URL The URL the Data Connector will forward events to. As we use webhook.site in this example, navigate to to generate a new URL on the form https://webhook.site/<RANDOM_ID>. Copy this URL, and paste it into the Endpoint URL field of the Data Connector config.

Remember to save your Data Connector configuration at the bottom of the page.

Send a POST request to:

https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors

A request body with the following parameters is required.

{
    "type": "HTTP_PUSH",
    "displayName": "Example",
    "httpConfig": {
        "url": "<ENDPOINT_URL>"
    }
}

Example Usage

Using cURL with a Service Account for authentication, the following example creates a new Data Connector with a given name "Example" and a webhook.site endpoint which can be monitored at https://webhook.site/<RANDOM_ID>.

curl -X POST "https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors" \
    -u "<SERVICE_ACCOUNT_KEY_ID>":"<SERVICE_ACCOUNT_SECRET>" \
    -d '{"displayName": "Example", "type": "HTTP_PUSH", "httpConfig": {"url": "https://webhook.site/<RANDOM_ID>"}}'

Example Usage

Using our Python API with Service Account credentials for authentication, the following example creates a new Data Connector with a given name "Example" and a webhook.site endpoint.

import disruptive as dt

# Authenticate the package using Service Account credentials.
dt.default_auth = dt.Auth.service_account(
    key_id='<SERVICE_ACCOUNT_KEY_ID>',
    secret='<SERVICE_ACCOUNT_SECRET>',
    email='<SERVICE_ACCOUNT_EMAIL>',
)

# Create a new HTTP Push Data Connector called "Example".
new_dcon = dt.DataConnector.create_data_connector(
    project_id='<PROJECT_ID>',
    config=dt.DataConnector.HttpPushConfig(
        url='https://webhook.site/<RANDOM_ID>',
    ),
    display_name='Example',
)

# Print the newly created Data Connector.
print(new_dcon)

Test Your Data Connector

The simplest way of testing your connection is by forwarding an event in one of the following ways.

  • Touching a sensor to force an emitted event.

Once an event has been forwarded by the Data Connector, each event will be visible as individual requests at the generated webhook.site URL.

You can verify that an event has been successfully forwarded by looking at the Data Connector metrics.

The Data Connector metrics can be found at the top of the Data Connector page in Studio.

Send a GET request to:

https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATACONNECTOR>:metrics

The response contains the metrics for the specified Data Connector over the last 3 hours.

{
  "metrics": {
    "successCount": 44,
    "errorCount": 0,
    "latency99p": "0.663s"
  }
}

Example

Using cURL with a Service Account for authentication, the following example requests the metrics for the specified Data Connector in the specified Project.

curl -X GET "https://api.d21s.com/v2/projects/<PROJECT_ID>/dataconnectors/<DATA_CONNECTOR_ID>:metrics" \
    --user "<SERVICE_ACCOUNT_KEY_ID>":"<SERVICE_ACCOUNT_SECRET>"

Example Usage

Using our Python API with Service Account credentials for authentication, the following example requests the metrics for the specified Data Connector in the specified Project.

import disruptive as dt

# Authenticate the package using Service Account credentials.
dt.default_auth = dt.Auth.service_account(
    key_id='<SERVICE_ACCOUNT_KEY_ID>',
    secret='<SERVICE_ACCOUNT_SECRET>',
    email='<SERVICE_ACCOUNT_EMAIL>',
)

# Fetch the metrics of the specified Data Connector.
metrics = dt.DataConnector.get_metrics(
    data_connector_id='<DATA_CONNECTOR_ID>',
    project_id='<PROJECT_ID>',
)

# Print the content of metrics.
print(metrics)

If the Error counter is incrementing, it indicates that DT Cloud is unable to forward events to your endpoint. This can be for any of the following reasons:

  • You have entered an incorrect Endpoint URL in the Data Connector config.

  • If you're forwarding events to a cloud function, make sure the cloud function is publicly available and does not require authentication. Otherwise, DT Cloud will receive 401 or 403 error codes from your endpoint.

  • Check your error logs for any other issues.

A list of all available parameters can be found in our .

Once the package is installed and authenticated as described in the , a new Data Connector can be created by calling the following resource method.

Wait for a sensor in the project to naturally emit an event by its .

Use the to emulate an emitted event.

Once the package is installed and authenticated as described in the , Data Connector metrics can be fetched by calling the following resource method.

An invalid SSL certificate has been configured on the server. See for more details.

REST API Reference
Python API Reference
disruptive.DataConnector.create_data_connector()
Sensor Emulator
Python API Reference
disruptive.DataConnector.get_metrics()
webhook.site
Service Account
webhook.site
Configuring a Data Connector
DT Studio
https://webhook.site
Server Configuration
periodic heartbeat
role