Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microsoft Graph API Select and Filter Owner Address in Calendar

I am trying to use Microsoft Graph Api to get and filter the address owner, and the address name of the calendars.

The permissions of my app are: enter image description here

enter image description here

enter image description here

I try to run this queries:

https://graph.microsoft.com/v1.0/me/calendars?$filter=owner/name eq 'Megan Bowen'

https://graph.microsoft.com/v1.0/me/calendars?$filter=owner/address eq '[email protected]'

But the response is "ErrorInternalServerError"

enter image description here enter image description here

Why this queries have problems? How select a property of specific type?

https://graph.microsoft.com/v1.0/me/calendars?$select=owner/name

Thanks,

enter image description here

like image 681
Eduardo Isaac Ballesteros Avatar asked Jul 19 '18 17:07

Eduardo Isaac Ballesteros


People also ask

What is delegated permission in graph API?

Delegated permissions are used by apps that have a signed-in user present. For these apps, either the user or an administrator consents to the permissions that the app requests and the app can act as the signed-in user when making calls to Microsoft Graph.

How can multiple requests be executed in a batch request?

Individual requests can be executed in a specified order by using the dependsOn property. This property is an array of strings that references the id of a different individual request.


1 Answers

Accessing calendars with Graph requires some configuration in permissions before the Graph call will work. What is required relates to the type of application and that drives the type of permissions – Delegate or Admin.
Below is information to help understand and help setting up the needed permissions.

Starting information:

For Graph to read from a shared mailbox (similar to Outlook delegate access), you need to set permissions in Azure and may also need to set sharing permissions. If you set Calendars.Read.Shared permissions then the user would need to share their calendar. If you set Calendars.Read for your application, then it can access all calendars in the org – there is no way to filter the scope.

Microsoft Graph permissions reference

Look under "Microsoft Graph permission names" and "Calendar permissions"

In Azure, set:

Calendars.Read.Shared permissions: Allows the app to read events in all calendars that the user can access, including delegate and shared calendars. (Delegated permissions)

or

Calendars.Read: Allows the app to read events of all calendars without a signed-in user. (Application Permissions)

It's the same for REST:

Outlook Calendar REST API reference

See "Using the Calendar REST API"

Delegate permissions:

For delegate permissions, three things are needed:

Calendar.Read.Shared or Calendar.ReadWrite.Shared in Azure. The user also needs to grant shared permission to the calendar. In the scope of requested permissions in your code, ask for the same permissions you granted in Azure. Here is how a user can share their calendar for an application using Delegate permissions:

Calendar sharing in Office 365

Share an Outlook calendar with other people

Admin permissions:

For Admin permissions (used by Background services or daemons Applications), Admin consent will need to be granted for Calendar.Read or Calendar.ReadWrite. This will allow the application to access all mailboxes in the organization. These permissions cannot be filtered to anything less than all mailboxes.

Get access without a user

Additional:

How to get a list of Shared mailboxes and users with permissions to those mailboxes in Exchange Online?

Be sure to also read the following, which covers how the credentials flow:

Azure Active Directory v2.0 and the OAuth 2.0 client credentials flow

Information on permission scopes:

Scopes, permissions, and consent in the Azure Active Directory v2.0 endpoint Permission scopes | Graph API concepts

If all permissions are set correctly
Then you should be able to do a rest call with this query:

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

Here [email protected] needs to be the UserPrincipalName of the user you wish to look up.

As a side note, any REST query you make with spaces in it will fail. If you need to call something with spaces, you need the querystring to escape the space with %20

like image 119
Henrik Stanley Mortensen Avatar answered Oct 03 '22 22:10

Henrik Stanley Mortensen