Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Answered

Microsoft Project CRUD operations API

Posted on by 24
Hi,

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?
  • Verified answer
    MattDC Profile Picture
    MattDC 24 on at
    Microsoft Project CRUD operations API
    I had the wrong scope for my MSAL request. I changed it to:

    ```
    const msalRequest = { scopes : [`https://${
        import.meta.env.VITE_MICROSOFT_DYNAMICS_ORG_ID
      }.api.crm4.dynamics.com/.default`] };
    ```


     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans