Skip to content

Commit 9726b84

Browse files
committed
Update article based on feedback
1 parent 807852d commit 9726b84

File tree

7 files changed

+38
-22
lines changed

7 files changed

+38
-22
lines changed

content/arduino-cloud/01.getting-started/08.arduino-iot-api/arduino-iot-api.md

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
---
2-
title: 'Arduino Cloud API & SDK'
2+
title: 'Arduino Cloud REST API & SDK'
33
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.'
55
tags:
6-
- IoT Cloud API
6+
- IoT Cloud REST API
77
- JavaScript
88
- Python
99
- node.js
1010
- Golang
1111
author: 'Karl Söderby'
1212
---
1313

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.
1515

1616
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.
1717

@@ -54,33 +54,49 @@ To authenticate, you will need to generate a `clientId` and `clientSecret`. This
5454

5555
![API Keys in the Arduino Cloud](assets/api-keys.png)
5656

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+
![Your Thing ID in the Metadata tab.](assets/thing-id.png)
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+
5774
## Postman
5875

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**.
6077

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:
6279

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+
![Authorization (step 1).](assets/postman-1.png)
7281

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.
7483

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+
![Authorization (step 2).](assets/postman-2.png)
7685

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+
![Token button.](assets/access-token.png)
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:
8096

81-
Then, in the **Authorization** tab, select **"Type > OAuth 2.0"** and paste the access token in the field.
97+
![GET Request for dashboards.](assets/get-request.png)
8298

83-
![Adding access token.](assets/postman.png)
99+
***Note that your access token expires after `300` seconds. After that, you will need to re-generate it by clicking the button again.***
84100

85101
## JavaScript (node.js)
86102

Loading
Loading
Loading
Loading
Binary file not shown.
Loading

0 commit comments

Comments
 (0)