[Solved] Access is denied - Check credentials and try again - Microsoft Graph - Calendar API

Access is denied - Check credentials and try again - Microsoft Graph - Calendar API
Microsoft Graph (Source: microsoft.com)


When sending API request to Microsoft Graph API, it responds with access denied error. You might have followed the documentation and added the correct permission and granted admin consent for the same, but it still produces the same error. Lets check the solution for this issue in this short article.


Error Message:


{'error': {'code': 'ErrorAccessDenied', 'message': 'Access is denied. Check credentials and try again.'}}


Error Scenario:

This issue occurs while sending GET request to Microsoft Graph CalendarView resource.


GET /users/{id | userPrincipalName}/calendars/{id}/calendarView?startDateTime={start_datetime}&endDateTime={end_datetime}


Possible Reason:

As the error message clearly suggests, in most scenarios - Microsoft Graph API responds with this error message when there is a permission issue.


Permissions Required:

For reading users calendar from application requires following permissions with type of Application Permission. 


Calendars.Read OR Calendars.ReadWrite


Workaround:

This issue may occur due to many reasons. You could try one of the following solutions to fix this issue.


Verify and remove the excessive permissions:

Check the least required access for the given request and remove all other access. In this case for accessing calendarview endpoint - Calendars.Read permission is sufficient remove all other permissions including the Calendars.ReadBasic.All permission.


O365 Subscription:

Verify and ensure, the Azure tenant which you have connected has the O365 subscription to access users Calendars / required resource.


Reassigning permissions

Remove and Revoke the permissions and grant it again - simply removing the permission not sufficient, have to revoke the Admin consent and add permission and grant consent again.


Creating a new application

Delete the existing application and register a new application - if none of the above workarounds resolved the issue, try deleting and existing application and register a new one with correct permission.


Hope this guide helps to resolve this issue, if you are able to fix this issue using any other method, please mention it in comment section for the benefit of other readers. Thanks!







0 thoughts:

Post a Comment