Get outlook contacts using @azure/msal-react but get error Resource could not be discovered.

Nam Nguyen Duc 0 Reputation points
2023-03-23T15:07:11.3333333+00:00

I'm using this tutorial to login to my registered app on my default AAD.

I want to get contacts from my outlook contact so I added Contacts.Read delegated permission.

I login (after consent my app for read contacts) and successfully get https://graph.microsoft.com/v1.0/me from /me endpoint using token returned to my app.

But when I use that token to get https://graph.microsoft.com/v1.0/me/contacts endpoint I get 404 error:

{

"error": {

"code": "ResourceNotFound",

"message": "Resource could not be discovered.",

"innerError": {

"date": "2023-03-23T14:50:53",

"request-id": "d4e9c0cc-06f4-4c2a-9969-7889a968f5ba",

"client-request-id": "d4e9c0cc-06f4-4c2a-9969-7889a968f5ba"

}

}

}

I tested with graph explorer and I can retrieve my contacts but when using authorization code flow to get token I get above errors.

I'm not sure why this happen, am i miss something?

Thank you very much User's image

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,855 questions
{count} votes

1 answer

Sort by: Most helpful
  1. HarmeetSingh7172 4,811 Reputation points
    2023-03-23T23:04:27.1133333+00:00

    Hello Nam Nguyen Duc

    Thanks for reaching out!

    Generally, this error - "Resource could not be discovered" - occurs when users are not assigned with Exchange license, or the mailbox is not configured for them. Please check and confirm if there is a mailbox present/active for this specific user. Ensure that the user's mailbox is not inactive, soft-deleted, or is hosted on-premises.

    Additionally, you can check whether the token generated from authentication method has the right permissions to access the List Contacts API. You can decode the generated token on https://jwt.ms/ and check for permissions under scp/roles property. Please use an API client like Postman to test the API with a token generated using auth code flow.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.