Share via

Microsoft Graph API, DELETE request response, "Access is denied. Check credentials and try again."

Abe Shaker 26 Reputation points
2021-03-17T20:53:22.04+00:00

Hello. I'm working on a short shell script to remove e-mails from three different inboxes. Our M365 admin successfully registered, configured and authorized an app which allows us to get an access token via script.

We can read e-mails successfully from all three accounts but cannot delete e-mails. The admin has confirmed that the API does have the Mail.ReadWrite permission as mentioned here. When I test this out on my own account using my own token it works fine. Is there another permission needed in order to do this? Thank you.

curl -X DELETE -H "Authorization: Bearer $AccessToken" "https://graph.microsoft.com/v1.0/me/messages/$EmailID"

Microsoft Security | Microsoft Graph

Answer accepted by question author

Danstan Onyango 3,996 Reputation points Microsoft Employee
2021-03-19T04:54:23.527+00:00

You can not use the token acquired using client_credentials grant type to call the /me and all its extensions because they required delegated permissions(signedin user). See here

Since you are using application permissions, you need to use https://graph.microsoft.com/v1.0/users/{user-id}/messages/{message-id} or any endpoint here that has no /me

Was this answer helpful?

2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

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