How to access shared calendars from Office REST API?
Asked Answered
A

3

7

This question has been asked several times and as per answers such as this it seems the API didn't support this then until recently as here which mentions that there are new scopes which allow accessing the shared calendars. But it still does not work.

I have tested this on two platforms: Azure and Microsoft Graph

  1. Azure Ad App

My application in Azure AD has all the required permissions: enter image description here

enter image description hereenter image description here

I make a call to Office API v.1.0 as:

Authorise URL:

https://login.microsoftonline.com/common/oauth2/authorize?client_id=%1$s&redirect_uri=%2$s&response_type=code

Token URL: https://login.microsoftonline.com/common/oauth2/token

Calendars URL: https://outlook.office.com/api/v1.0/Me/Calendars

It only gives me the calendar created by the current logged-in/authorising user.

Since this didn't work, I tried with the version 2 of the API but I got the following:

Additional technical information:
Correlation ID: 7abf370a-d918-4514-bd74-cf5fc93fe3cf
Timestamp: 2016-10-31 09:32:06Z
AADSTS70001: Application 'f7571710-84e2-4444-8bfe-5eef92f4a46d' is not supported for this API version.

So I tried with a Microsoft Graph Application

  1. Microsoft Graph App

My application here also contains all the required permissions.

enter image description here

I make call to the office API v2.0 as:

Authorize URL:

https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=%1$s&redirect_uri=%2$s&response_type=code&scope=%3$s

Where scopes are:

private static $scopes = array(
    'https://outlook.office.com/calendars.read',
    'https://outlook.office.com/calendars.readwrite',
    'https://outlook.office.com/calendars.read.shared',
    'https://outlook.office.com/calendars.readwrite.shared',
);

Token URL: https://login.microsoftonline.com/common/oauth2/v2.0/token

Calendars URL: https://outlook.office.com/api/v2.0/Me/Calendars

Again does not give me the shared calendars.

Any help is appreciated.

Ankylostomiasis answered 2/11, 2016 at 13:44 Comment(3)
Related: #31056223Ankylostomiasis
Related: #32501415Ankylostomiasis
Related: #28365524Ankylostomiasis
S
3

A lot of stuff going on here :) However it seems the crux here is that you're expecting /Me/Calendars to include shared calendars. It does not. In order to access someone else's calendar that has been shared, you must access via the /Users/<id>/Calendars/ URL.

So for example if [email protected] logs in, and [email protected] has shared his calendar with him, then:

  • /Me/Calendars would ONLY show calendars in Bob's mailbox
  • /Users/[email protected]/Calendars would show calendars Bill has shared with Bob

Update: It seems there's a blocking issue on our side. We're working on it.

Syllepsis answered 2/11, 2016 at 14:19 Comment(12)
Interesting. So is there a way to get users that have shared their calendar to the account?Ankylostomiasis
No there isn't. Note that even in Outlook you can't get this information, you have to know that the user shared with you.Syllepsis
I tried query /Users/../Calendars. It returned me with {"error":{"code":"ErrorItemNotFound","message":"The specified object was not found in the store."}}Ankylostomiasis
Full URL was https://outlook.office.com/api/v2.0/Users/[email protected]/CalendarsAnkylostomiasis
I'm really interested in reading events from shared calendars, but it seems that I still can't do that. I'd love an update when that gets fixed!Tman
Look at #44182675. Calendars shared under the "old" method are still not working with the API, we are working to fix that.Syllepsis
@JasonJohnston In OWA there seems to be a method for getting all the calendar groups with all their calendars, including calendars that were added via a share or because they are public within the organization. These appear in the left sidebar of the exchange UI and can be selected/deselected to affect the dropdown list that appears when creating an event and choosing which calendar to put the event on. We want to replicate that dropdown, which can contain shared calendars. Seems like the REST API doesn't list shared calendars in the groups they should be in (eg. "Peoples Calendars").Hofer
Understood. The REST APIs just don't expose this currently. Good feature to request on UserVoice!Syllepsis
@JasonJohnston Is there a way to accomplish this using EWS?Hofer
I'm not sure to be honest.Syllepsis
Is it still not possible? I've lost a day to this issue it seems. We just cannot access someone's calendar via the Graph API, not even if it's shared.Celebes
Funny thing is that it suddenly started working just now... didn't change anything since last test. But what we really want is write access to all calendars which is still not possible. Or we can't get it working.Celebes
C
1

I've been able to do what I believe you're asking about (using the Outlook API to get the events from calendars which have been shared with your outlook calendar) by using the following endpoint:

.../api/v2.0/Users('PRIMARY_USER_ID')/Calendars('SHARED_CALENDAR_ID')/Events

From this endpoint, you should be able to grab events/info from any calendar that has been directly shared with your outlook/office 365 account.

  • The PRIMARY_USER_ID (just what I'm calling it here) comes back to you as part of the response object when you first sign in with your outlook account and go through Microsoft's auth process. This isn't the ID of the calendar you're trying to access, but the ID of the primary calendar (the one you can find at the api/v2.0/me endpoint) that the other calendars are shared with. All of the IDs I've seen have come back in the form of a bunch of letters and numbers separated by dashes.

  • The CALENDAR_ID is the ID of the shared calendar you're trying to get the events from. You can see these IDs for each of your shared calendars if you make a request to .../api/v2.0/me/calendars/. This will return each of the calendars that are shared with you, info about the owner, and the 'ID' of that calendar.

If you plug in those ids, and make a request to url above, you should be able to get calendar events back from the API.

Custumal answered 24/5, 2017 at 17:5 Comment(0)
O
1

Updated. I found a working solution.

GET /users('{id}')/calendars('{id}')/events

GET /me/calendars('{id}')/events

There are a few rules for how you need to share it and can be found at: https://developer.microsoft.com/en-us/graph/docs/concepts/known_issues#calendars

An alternate workaround:

You can access group calendars and group events using the API. Group calendars can be shared with anyone inside or outside your organization. Rather than sharing a users calendar, simply create a Group, add any members who you want read/write access. As long as a user is a member of that group, any events added to the groups calendar, will come through in the standard /me/events GET request.

I found you need to have the following permissions granted:

  • Calendars.Read (Calendars.ReadWrite if write needed)
  • Calendars.Read.Shared (Calendars.ReadWrite.Shared if write needed)
  • Group.Read.All (Group.ReadWrite.All if write needed)

Good Luck!

Oligopsony answered 25/6, 2017 at 11:7 Comment(1)
Thanks for the helpful tips.Ankylostomiasis

© 2022 - 2024 — McMap. All rights reserved.