authorization issues error 401
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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);
}
}
```