I'm trying to access my Microsoft Project data from a client-side JavaScript app using this function:
export default async function getProjectEntities() {
try {
const accessToken = await getToken();
if (!accessToken) {
throw new Error('Access token is missing');
}
const apiUrl = 'https://<orgid>.api.crm4.dynamics.com/api/data/v9.1/msdyn_projects';
const response = await fetch(apiUrl, {
method : 'GET',
headers : {
'Authorization' : `Bearer ${accessToken}`,
'OData-MaxVersion' : '4.0',
'OData-Version' : '4.0',
'Accept' : 'application/json',
'Content-Type' : 'application/json'
}
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data;
}
catch (error) {
console.error('Error fetching project entities:', error);
throw error;
}
}
```
I get the access token using MSAL library:
```
const msalConfig = {
auth : {
clientId : import.meta.env.VITE_MICROSOFT_ENTRA_APP_ID,
authority : `https://login.microsoftonline.com/${
import.meta.env.VITE_MICROSOFT_ENTRA_TENANT_ID
}`,
redirectUri : 'http://localhost:5173'
}
};
```
I have an app registered in Microsoft Entra
I get a 401 Unauthorized error when trying to fetch the project data.
I have used this access token to access 365 data using Microsoft Graph, but I see that Project is not in the Microsoft Graph API.
Am I missing an auth step?