manish kumar
manish kumar

Reputation: 21

How to get users calendar event in microsoft graph api

I have registered an app in the azure portal for an organization. With the graph api I am able to access all users present in the tenant using graph api graph.microsoft.com/v1.0/users.

This is the process that I am using to get an individual user's calendar:

  1. graph.microsoft.com/v1.0/users.
  2. copy id/userPrincipalName of a user.
  3. graph.microsoft.com/v1.0/users/id/calendars/events.

In this process I am getting 403 forbidden.

Please let me know if my approach is correct or not.

Upvotes: 2

Views: 14823

Answers (1)

Allen Wu
Allen Wu

Reputation: 16438

403 means that your Azure AD app doesn't have enough permissions to access the events.

If you are using Get access without a user, you need add Calendars.Read, Calendars.ReadWrite Application permissions into your app.

If you are using Get access on behalf of a user, you need to add Calendars.Read, Calendars.ReadWrite Delegated permissions into your app.

See the required permissions from List events Permissions.

For how to add API permissions, you could refer to Manage API permission.


Update

Take Application permission: Calendars.Read as an example.

After you add the permission in Azure AD app, don't forget to click on the "Grant admin consent for ***" button at the bottom. enter image description here

And then use Get access without a user to get the access token. enter image description here

After getting the access token, call the calendar events endpoint. enter image description here

The format of the value of Authorization is "Bearer {access_token from the last step}".


Update 2: enter image description here

Upvotes: 5

Related Questions