Search code examples
azureazure-active-directorymicrosoft-graph-api

GraphAPI - can't get calendar events for any other user except myself


I don't understand the problem. My user is the administrator of a test Azure directory and I have dummy users that were setup automatically. I can get calendar events for myself using my email just fine:

https://graph.microsoft.com/v1.0/users/[email protected]/calendar/events

but whenever I try to retrieve calendar events from any other dummy user (by just switching the email address in GraphAPI request URL), I get the following error in Graph Explorer:

"code": "ErrorItemNotFound",
"message": "The specified object was not found in the store.",

The dummy users I'm trying to retrieve events for have multiple events in their calendars so empty calendar is definitely not an issue.

I have set up my permissions in Azure AD/App registrations/API permissions:

enter image description here

I can't figure out what detail/setting/permission I'm missing.


Solution

  • I tried to reproduce the same in my environment and got below results:

    I registered one Azure AD application and added same API permissions as below:

    enter image description here

    When I ran the same query in Graph Explorer, I can get calendar events for myself using my email like below:

    GET https://graph.microsoft.com/v1.0/users/[email protected]/calendar/events
    

    Response:

    enter image description here

    But when I tried to retrieve calendar events of other user, I got same error like below:

    GET https://graph.microsoft.com/v1.0/users/[email protected]/calendar/events
    

    Response:

    enter image description here

    The error occured as Graph Explorer uses Delegated permissions but retrieving other user calendar events require Application permissions.

    As you already assigned Application permissions in your application, just generate an access token using client credentials flow and use it to run Graph queries.

    In my case, I used Postman to generate access token with client credentials flow like below:

    POST https://login.microsoftonline.com/<tenantID>/oauth2/v2.0/token
    grant_type:client_credentials
    client_id:<appID>
    client_secret:<secret>
    scope:https://graph.microsoft.com/.default
    

    Response:

    enter image description here

    When I used this token to run below graph query, I got calendar events of other user successfully like this:

    GET https://graph.microsoft.com/v1.0/users/[email protected]/calendar/events
    

    Response:

    enter image description here