with cURL
A quick showcase of how cURL can be used to explore the various calls available on our REST API.

Overview

We will here show how cURL can be used to interact with our REST API. As an example, Basic Auth will be used to authenticate a GET request that fetches a list of available projects. All available endpoints are listed in our REST API Reference.

Prerequisites

cURL

cURL is a command-line tool that can be used to easily make arbitrary HTTP requests. This includes our entire API which can be accessed via a single cURL command. Detailed information about the parameters used can be found under cURLs manpage, man curl.

Installation

The tool comes preinstalled on most Linux and Mac systems. You can verify the install by opening your favorite shell and typing which curl , and are otherwise readily available in most package managers.
    Debian-based distributions: apt install curl
    Arch-based distributions: pacman -S curl
    Mac: brew install curl
    Windows: The cURL client binary can be found here.

GET Request

The following command will fetch a list of all available projects for a Service Account.
1
curl -X GET "https://api.disruptive-technologies.com/v2/projects" \
2
-u "<YOUR_SERVICE_ACCOUNT_KEY_ID>":"<YOUR_SERVICE_ACCOUNT_SECRET>"
Copied!
    -X <command> Specifies the HTTP request method and to which URL it is sent. The method, usually GET or POST, should be changed to accommodate the target URL.
    -u <user:password> Specifies the user for authentication. We use a Service Account, and the key-id and secret can be found when creating the account, as explained in the Basics of Service Accounts.
If the valid key-id and secret of a Service Account with sufficient privileges were used, cURL should return a list of the available project for that account to stdout.
1
{"projects":[{"name":"projects/btadoe94jplfdvvdr6q0","displayName":"wCaV7Y",
2
"organization":"organizations/b9spme0i0da0037ge49g","organizationDisplayName":
3
"Disruptive Technologies Research","sensorCount":10,"cloudConnectorCount":1,
4
"inventory":false}],"nextPageToken":""}
Copied!

POST Request

The following command adds the label my-new-label with value some-value to the specified device.
1
curl -X POST "https://api.d21s.com/v2/projects/<YOUR_PROJECT_ID>/devices/<YOUR_DEVICE_ID>/labels" \
2
-u "<YOUR_SERVICE_ACCOUNT_KEY_ID>":"<YOUR_SERVICE_ACCOUNT_SECRET>" \
3
-d '{"key": "my-new-label", "value": "some-value"}'
Copied!
    -X <command> Specifies the HTTP request method and to which URL it is sent. The method, usually GET or POST, should be changed to accommodate the target URL.
    -u <user:password> Specifies the user for authentication. We use a Service Account, and the key-id and secret can be found when creating the account, as explained in the Basics of Service Accounts.
    -d <data> Sends the specified data in a POST request to the HTTP server.
If the valid key-id and secret of a Service Account with sufficient privileges were used, cURL should return a list of the available project for that account to stdout.
1
{
2
"name": "projects/<YOUR_PROJECT_ID>/devices/<YOUR_DEVICE_ID>/labels/my-new-label",
3
"key": "my-new-label",
4
"value": "some-value"
5
}
Copied!

Optional Formatting

cURL alone makes no attempt at formatting its output. By piping the cURL output through a command-line JSON processor like jq, the result is much more readable.
1
curl <insert-command-here> | jq
Copied!
The same response as previously now looks like the following.
1
{
2
"projects": [
3
{
4
"name": "projects/btadoe94jplfdvvdr6q0",
5
"displayName": "wCaV7Y",
6
"organization": "organizations/b9spme0i0da0037ge49g",
7
"organizationDisplayName": "Disruptive Technologies Research",
8
"sensorCount": 10,
9
"cloudConnectorCount": 1,
10
"inventory": false
11
}
12
],
13
"nextPageToken": ""
14
}
Copied!
Last modified 7mo ago