How to get calendar events for a room using list events REST API?

Віталій Мазуренко 20 Reputation points
2024-04-02T18:01:00.0133333+00:00

Context

The use case of my application:

  1. User should be able to link Microsoft 365 organization to the app.
  2. User should be able to see all rooms in the organization. Currently, I use "List places" API: GET /places/microsoft.graph.room
  3. User should be able to see how the room is used historically, some kind of occupancy analytics.

The current plan is:

  1. Make an initial fetch of the last N-months of events for a room using the "List events" API and persist those in the DB. GET /users/room1@someorg.onmicrosoft.com/events
  2. Subscribe to the new events via Event Hub to catch newly created events.
  3. Build some analytics based on the stored events.

Problem

I cannot fetch events for a room because of permission issues.

GET /users/room1@someorg.onmicrosoft.com/events

returns 403 error with payload

{
    "error": {
        "code": "ErrorAccessDenied",
        "message": "Access is denied. Check credentials and try again."
    }
}

Prerequisites:

  1. My user is a full admin of the organization
  2. All necessary permissions are acquired while creating an access token: Calendars.ReadBasic, Calendars.Read, Calendars.ReadWrite

The solution I found:

Add myself to the Delegates list of the room I want to get events from. It could be managed in the Edit room view of the Microsoft 365 admin center.

Unfoturenetly, this doesn't look like a working solution for production, as I would need to ask our end users to make that setting change in their admin center. And also it looks like Delegates setting is designed for other reasons.

Question

How to get the calendar events for a room avoiding the permission issues I described? The solution should also take into account the intention to receive the events updates using the Event Hub subscriptions.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,446 questions
0 comments No comments
{count} votes

Accepted answer
  1. CarlZhao-MSFT 36,336 Reputation points
    2024-04-03T08:53:20.48+00:00

    Hi @Віталій Мазуренко

    The /users/{user_id} endpoint only supports application context and not delegated context, so you should use the daemon-based client credentials flow to request the token. Before doing this, you need to grant the Calendars.Read application permission to the calling app.

    Hope this helps.

    If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful