Search code examples
microsoft-graph-apimicrosoft-graph-teamsmicrosoft-graph-mailmicrosoft-graph-calendar

how can i get user's calender data with microsoft graph get request


My main purpose is to get User's calender by single admin access token. i am trying to get access token by following these steps.

URL :https://login.microsoftonline.com/{tenentId}/oauth2/v2.0/token Body client_id:client_ID scope:https://graph.microsoft.com/.default client_secret:client_secretID grant_type:client_credentials

this give me an access token but when i change the scope to scope:https://graph.microsoft.com/Calendars.Read
it gives error

URL :https://login.microsoftonline.com/{tenentId}/oauth2/v2.0/token Body client_id:client_ID scope:https://graph.microsoft.com/Calendars.Read client_secret:client_secretID grant_type:client_credentials

it did not return access token and says "error": "invalid_scope",

i will be very thankfull if anyone can help. thanks in advance


Solution

  • For Client Credential Flow you need to specify the Application permission - Calendars.Read and grant admin consent to it. As you are using scope:https://graph.microsoft.com/.default this would get all the permissions you specified in the Azure AD App you created. Then it will include the Calendars.Read permission in your access token which would allow to get usier's calendar.

    https://graph.microsoft.com/v1.0/users/{user_id/UPN}/calendars