API Key Generation page not available on home screen

I believe I have two issues, that might be related to one another.

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

  1. 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?

Hi @aschanen

Thanks for reporting this! The Arduino Cloud website was recently redesigned and the navigation to the API keys management interface changed but the documentation was not updated accordingly.

I submitted an update for the affected documentation:

Great job on finding that even without correct guidance from the documentation.

In case you (or others who find this discussion in the future while searching for the information) would like to know how to navigate to that page through the modern Arduino Cloud site interface:

  1. Open the Arduino Cloud home page: https://app.arduino.cc/
  2. Log in to your account if you are not already.
  3. Click on your username at the top left corner of the page:
    image
    The account management menu will open.
  4. Select "API Keys" from the menu:
    image

The "API Keys" page will now open.

It might be worth checking whether you get the same result when using the Arduino Cloud CLI tool with the same credentials:

  1. Follow these instructions to install Arduino Cloud CLI:
    https://docs.arduino.cc/arduino-cloud/arduino-cloud-cli/getting-started#installation
    It is just a simple single file executable, so don't worry that the installation is going to be some big ordeal that adds a lot of clutter to your system.
  2. Run the following command:
    arduino-cloud-cli credentials init
    
  3. Enter the same client ID and secret at the prompts as you are using in your JavaScript code.
  4. Run the following command:
    arduino-cloud-cli device list
    

When I performed the instructions above, the list of my devices was printed as expected.

I now have the cloud CLI installed, looks like this too also brings up an empty device list.

I did not fill out the organization ID (as I only have a space ID for the enterprise space we are using) Does that need to be filled out?

You can get your enterprise workspace ID going to "Space Settings" on the navigation panel on the left.

It looks like it was a missing organization ID that was causing the device list to appear empty, apparently it is not as optional as the CLI or API documentation leads me to believe.

Also maybe a change to the term "organization id" is in order? I understand key names don't always match the titles in the UI but to me an "organization" seems like a level above "space", not an equivalent.

In what situation does an organization ID not exist? Just out of curiosity.

In any case, thanks everyone for all the help! I was able to get this working now.

In Arduino Cloud there are plans for Individuals, Businesses and Schools.

Plans for Individuals (Entry, Maker and Maker Plus) don't support multiple workspaces and, consequentely, they don't require an organization ID :blush: .

Good to know! Thank you again!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.