Disruptive Technologies Disruptive Developers

cURL

You might have noticed that when using the Try it out functionality, you also get an auto-generated “curl” command for that specific request.

curl is a command line tool which can be used to easily make arbitrary HTTP requests. In fact, it’s possible to use our entire API via curl commands.

Installing curl

curl comes pre-install on a lot of Linux and OS X systems. First open up your favorite console and check if you already have curl installed by running curl --version. If it lists a version, you already have it installed.

If it’s not found, then install it using your favorite package manager, such as

  • apt-get install curl on Debian-based Linux distributions or
  • brew install curl on OS X.
  • On Windows, download the curl client binary from here

Using cURL

The curl command for any given API call is auto-generated when the Try it out functionality is used. For example, when using Try it out on GET /projects and you press Execute you will see something like:

curl -X GET "https://api.disruptive-technologies.com/v2/projects" \
  -H "accept: application/json" \
  -H "Authorization: Bearer YOUR-TOKEN-HERE"

To test it out, simply copy-paste this from your browser (you need your unique Bearer Token) and run this request in the command line console.

Next Steps - Service Account

When you copy-paste the curl command from the API Reference, you get a “token” that is valid for about one hour. This token was generated when you authorized the Interactive API client by clicking Authorize.

To get more permanent credentials for your development, please see how to set up a Service Account in the Code Example.

When you’ve done that, it’s possible to run the above curl command with Basic Auth like:

curl -X GET "https://api.disruptive-technologies.com/v2/projects" \
  -H "accept: application/json" \
  -u SERVICE_ACCOUNT_KEY_ID:SERVICE_ACCOUNT_KEY_SECRET



Optional - jq

To get pretty formatting and JSON highlighting in the console, look into installing a small tool called jq for Your Platform.

With this installed pretty-printing results is as easy as:

curl -X GET "https://api.disruptive-technologies.com/v2/projects" \
  -H "accept: application/json" \
  -u SERVICE_ACCOUNT_KEY_ID:SERVICE_ACCOUNT_KEY_SECRET \
  | jq

This will make e.g. the following output without jq:

{"projects":[{"name":"projects/a8rsrqnh24qg00c0s9bg","displayName":"My Project","organization":"organizations/dt", \
"organizationDisplayName":"Disruptive Technologies","sensorCount":5,"cloudConnectorCount":1}],"nextPageToken":""}

Look like this with jq:

{
  "projects": [
    {
      "name": "projects/a8rsrqnh24qg00c0s9bg",
      "displayName": "My Project",
      "organization": "organizations/dt",
      "organizationDisplayName": "Disruptive Technologies",
      "sensorCount": 5,
      "cloudConnectorCount": 1
    }
  ],
  "nextPageToken": ""
}

To pipe stream API calls to jq, you need to use standard application/json and not buffer the output stream, like so:

curl -X GET "https://api.disruptive-technologies.com/v2/projects/a8rsrqnh24qg00c0s9bg/devices:stream" \
  -H "accept: application/json" \
  -u SERVICE_ACCOUNT_KEY_ID:SERVICE_ACCOUNT_KEY_SECRET \
  --stderr /dev/null -N | jq