authorization issues error 401

authorization issues error 401

karsten_duim
Community Visitor Community Visitor
634 Views
0 Replies
Message 1 of 1

authorization issues error 401

karsten_duim
Community Visitor
Community Visitor

I seem to keep getting the 401 error not authorized

the ClientID and ClientSecret are correct and went by loads of other steps can't figure out what keeps going wrong

 

```

// Define your Forge client ID and client secret
const clientId = '(hidden for security)';
const clientSecret = '(hidden for security)';

 

// Define global variables
let accessToken = null;
let projectId = null;
let itemId = null;

 

// Function to obtain an access token
async function getAccessToken() {
try {
const response = await fetch('https://developer.api.autodesk.com/authentication/v2/token', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `client_id=${clientId}&client_secret=${clientSecret}&grant_type=client_credentials&scope=data:read`
});

if (!response.ok) {
throw new Error('Failed to obtain access token');
}

const data = await response.json();
accessToken = data.access_token;
} catch (error) {
console.error('Error obtaining access token:', error);
}
}


```

0 Likes
635 Views
0 Replies
Replies (0)