Cloud Client API Auth with Javascript

I'm trying to access details of my IoT Cloud Dashboard using Javascript and keep getting 401 errors (Unauthorized) errors, but most other API calls appear to work correctly. The code I am using to call the Dashboards API is below, and I am the getToken function from the example, with devices and things both returning useable values. So, I'm just wondering if anyone could advise what I'm missing! Alternatively, I am looking at creating a bespoke web dashboard that uses the API, so if there is an easier method for handling this, I'd be happy to discuss it!

async function listProperties() {
    var client = IotApi.ApiClient.instance;
    var oauth2 = client.authentications['oauth2'];
    oauth2.accessToken = await getToken();

    var api = new IotApi.DashboardsV2Api(client)
	api.dashboardsV2List().then(function(data) {
		console.log(data);
	}, function(error) {
		console.error(error);
	});
}

listProperties();

@adrianforrester i am also getting the same error. Did you gotta any solution on that?

I found the solution, actually its a small bug in offical sdk files. firstly remove the client as parameter from DashboardsV2API method. Then Navigate to your Directory where you have NodeJS SDK for Arduino IoT Cloud. Navigate to dist > api and open up the DashboardV2API.js and replace var authNames =[]; with var authNames = ['oauth2']; in the whole file and you will be good to go.

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