Getting response as "Access is denied. Check credentials and try again" while calling the api to get messages

Shamsul Zama 0 Reputation points
2024-04-03T09:56:26.15+00:00

I used the Microsoft Graph sample Ruby on Rails app to setup a ruby on rails application. After authentication, access token and refresh token are stored in the database.
When the List Messages Api is called using this access token. I am getting the below error from the response.

response = HTTParty.get("https://graph.microsoft.com/v1.0/me/messages", :headers => {
  "Scope" => "Mail.Read",
  "Content-Type" => "application/json",
  "Authorization" => "Bearer #{user.access_token}"
})

{"error"=>{"code"=>"ErrorAccessDenied", "message"=>"Access is denied. Check credentials and try again."}}

I have attached the screenshot of permissionScreenshot 2024-04-03 at 11.28.57 AM

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

1 answer

Sort by: Most helpful
  1. CarlZhao-MSFT 40,311 Reputation points
    2024-04-04T08:39:18.7533333+00:00

    Hi @Shamsul Zama

    It works fine for me. Please decode your access token and check the scp claim to make sure it contains one of the Mail.ReadBasic, Mail.ReadWrite or Mail.Read permissions.

    User's image

    Hope this helps.

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