|
1 | 1 | ---
|
2 |
| -title: 'Arduino Cloud API & SDK' |
| 2 | +title: 'Arduino Cloud REST API & SDK' |
3 | 3 | difficulty: advanced
|
4 |
| -description: 'Learn how to authenticate with the Arduino IoT Cloud API to make requests using HTTP Client, JavaScript and Python.' |
| 4 | +description: 'Learn how to authenticate with the Arduino IoT Cloud REST API to make requests using HTTP Client, JavaScript and Python.' |
5 | 5 | tags:
|
6 |
| - - IoT Cloud API |
| 6 | + - IoT Cloud REST API |
7 | 7 | - JavaScript
|
8 | 8 | - Python
|
9 | 9 | - node.js
|
10 | 10 | - Golang
|
11 | 11 | author: 'Karl Söderby'
|
12 | 12 | ---
|
13 | 13 |
|
14 |
| -The [Arduino IoT Cloud API](https://www.arduino.cc/reference/en/iot/api/) can be accessed through a set of endpoints to manage **Devices, Things, Properties** and more. It can be accessed via any HTTP client, and is supported by JavaScript, Python and Golang clients. |
| 14 | +The [Arduino IoT Cloud REST API](https://www.arduino.cc/reference/en/iot/api/) can be accessed through a set of endpoints to manage **Devices, Things, Properties** and more. It can be accessed via any HTTP client, and is supported by JavaScript, Python and Golang clients. |
15 | 15 |
|
16 | 16 | In this article you will find some useful examples to get started with the Arduino IoT Cloud API, and an understanding of what the API offers.
|
17 | 17 |
|
@@ -54,33 +54,49 @@ To authenticate, you will need to generate a `clientId` and `clientSecret`. This
|
54 | 54 |
|
55 | 55 | 
|
56 | 56 |
|
| 57 | +## Obtaining IDs |
| 58 | + |
| 59 | +All main components of the Arduino IoT Cloud have an `id` associated. You can access your **device, Thing & variable** `id` from the web interface. |
| 60 | + |
| 61 | +For example, your Thing ID is stored in the **"Metadata"** tab of your Thing. |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +You can also make a request that will return a list of the component and all information about it: |
| 66 | +- `https://api2.arduino.cc/iot/v2/things` - lists all Things and associated properties/variables. |
| 67 | +- `https://api2.arduino.cc/iot/v2/device` - lists all devices. |
| 68 | +- `https://api2.arduino.cc/iot/v2/dashboards` - lists all dashboard and associated widgets. |
| 69 | + |
| 70 | +You can make more specific requests to obtain only the information on a specific Thing, or a specific variable. |
| 71 | + |
| 72 | +***Note that you will need to pass the authentication token in the body when making any request to the Arduino Cloud REST API. The examples in this guide includes the generation of such token. For testing the API, you can follow the Postman setup just below.*** |
| 73 | + |
57 | 74 | ## Postman
|
58 | 75 |
|
59 |
| -[Postman](https://www.postman.com/) is a service that allows you to construct and make HTTP requests. In the panel, you can create a **workspace**. |
| 76 | +[Postman](https://www.postman.com/) is a service that allows you to construct and make HTTP requests. In the panel, you can create a **workspace**, and a new **HTTP request**. |
60 | 77 |
|
61 |
| -First, to authenticate, click on the **"Import > Raw Text"**, then add the following commands, replacing `YOUR_CLIENT_ID` and `YOUR_SECRET_ID` with your credentials. |
| 78 | +Before we can make requests to the API, we will need to generate an **access token**. To do so, you will need to configure the **"Authorization"** tab, according to the images shown below: |
62 | 79 |
|
63 |
| -``` |
64 |
| -curl --request POST \ |
65 |
| - --url 'https://api2.arduino.cc/iot/v1/clients/token' \ |
66 |
| - --header 'content-type: application/x-www-form-urlencoded' \ |
67 |
| - --data 'grant_type=client_credentials' \ |
68 |
| - --data 'client_id=YOUR_CLIENT_ID' \ |
69 |
| - --data 'client_secret=YOUR_SECRET_ID' \ |
70 |
| - --data 'audience=https://api2.arduino.cc/iot' |
71 |
| -``` |
| 80 | + |
72 | 81 |
|
73 |
| -This will import all necessary configurations. Click on **"Send"** and you will receive an access token (note that it has an expiry time, 300 seconds). Copy it. |
| 82 | +Now, click on the **"Advanced Options"** tab, and add `https://api2.arduino.cc/iot` to the **"Audience"** field. |
74 | 83 |
|
75 |
| -We can now create a new request to e.g. list out properties by first importing the following command (note that you need to replace `{id}` with a Thing ID). |
| 84 | + |
76 | 85 |
|
77 |
| -``` |
78 |
| -curl -X GET "https://api2.arduino.cc/iot/v2/things/{id}/properties |
79 |
| -``` |
| 86 | +Finally, click on the **"Get New Access Token"**. |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +You now have an access token that has an expiry of `300` seconds, and we can make requests to the API. |
| 91 | + |
| 92 | +You can for example try |
| 93 | +- **GET** | `https://api2.arduino.cc/iot/v2/dashboards` |
| 94 | + |
| 95 | +Which should look like this in the Postman UI: |
80 | 96 |
|
81 |
| -Then, in the **Authorization** tab, select **"Type > OAuth 2.0"** and paste the access token in the field. |
| 97 | + |
82 | 98 |
|
83 |
| - |
| 99 | +***Note that your access token expires after `300` seconds. After that, you will need to re-generate it by clicking the button again.*** |
84 | 100 |
|
85 | 101 | ## JavaScript (node.js)
|
86 | 102 |
|
|
0 commit comments