I believe I have two issues, that might be related to one another.
- Following many tutorials to get the IOT cloud API working, they all seem to have the "API Keys section" on the left side menu. I am on the enterprise plan and don't see this option.
The option is not available under any sub-menus as well.
- When doing research, I found that this url https://app.arduino.cc/api-keys
allowed me to generate an api key within arduino cloud. So I did.
When I use this key that I obtained by navigating directly to the URL, it's seemingly has no permissions, or is unable to see any data within my cloud environment.
I have simple JS Code here to obtain the list of my devices. (I am the sole owner of the devices. I added them all, added all things associated with them, all sketches, and all dashboards)
var IotApi = require('@arduino/arduino-iot-client');
var axios = require('axios');
async function getToken() {
var url = 'https://api2.arduino.cc/iot/v1/clients/token';
var data = new URLSearchParams({
grant_type: 'client_credentials',
client_id: 'MY-CLIENT_ID',
client_secret: 'MY_CLIENT_SECRET',
audience: 'https://api2.arduino.cc/iot'
}).toString();
var config = {
method: 'post',
url: url,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data : data
};
try {
const response = await axios(config);
console.log(response.data['access_token'])
return response.data['access_token'];
}
catch (error) {
console.error("Failed getting an access token: " + error);
}
}
async function run() {
var client = IotApi.ApiClient.instance;
// Configure OAuth2 access token for authorization: oauth2
var oauth2 = client.authentications['oauth2'];
oauth2.accessToken = await getToken();
var api = new IotApi.DevicesV2Api(client);
api.devicesV2List().then(devices => {
console.log(devices);
}, error => {
console.log(error);
});
}
run();
This code runs fine, and console.log()
's out two values, the access token itself on line 24 and the list of devices on line 39
The data returned is as follows, no matter which list endpoint I use (devices, things etc...) I recieve back a valid access token, and an empty list of devices (or things, if the endpoint is changed)
RETURNED_ACCESS_TOKEN_STRING
[]
What is going on with this API key? My assumption is that it is not working because I've obtained it without going through the proper UI. Even at the token creation page, the left menu appears different than tutorial screenshots. Is this normal?