How to get calendar events or reservations from Room resource using Graph Client

Sumith Jose 26 Reputation points
2020-09-13T13:04:04.107+00:00

Hi I'm trying to get the events from the room mailbox using graph client. Like we retrieve events from the user calendar as follows.

var queryOptions = new List<QueryOption>()
        {
               new QueryOption("startDateTime", startDateTime),
               new QueryOption("endDateTime", endDateTime)
        };

       var calendarView = await graphClient.Users[{user_id}].CalendarView
             .Request(queryOptions)
             .GetAsync();

Is there any way to fetch events from the room calendar using graph client.

I need all reservations of room resources. That includes any user reservation in that room.

Any help is appreciated.

Exchange | Exchange Server | Management
Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Andy David - MVP 157.8K Reputation points MVP Volunteer Moderator
    2020-09-14T19:07:19.66+00:00

1 additional answer

Sort by: Most helpful
  1. soumi-MSFT 11,831 Reputation points Microsoft Employee Moderator
    2020-09-14T09:49:22.063+00:00

    @Sumith Jose , Thank you for reaching out. To get the schedule for a room, you can use the following Microsoft Graph API:

    HTTP:

    POST https://graph.microsoft.com/v1.0/me/calendar/getSchedule   
    Prefer: outlook.timezone="Pacific Standard Time"  
    Content-Type: application/json  
      
    {          
        "schedules": ["******@contoso.onmicrosoft.com", "******@contoso.onmicrosoft.com"],  
        "startTime": {  
            "dateTime": "2019-03-15T09:00:00",  
            "timeZone": "Pacific Standard Time"  
        },  
        "endTime": {  
            "dateTime": "2019-03-15T18:00:00",  
            "timeZone": "Pacific Standard Time"  
        },  
        "availabilityViewInterval": 60  
    }  
    

    For C#:

    GraphServiceClient graphClient = new GraphServiceClient( authProvider );  
      
    var schedules = new List<String>()  
    {  
    	"******@contoso.onmicrosoft.com",  
    	"******@contoso.onmicrosoft.com"  
    };  
      
    var startTime = new DateTimeTimeZone  
    {  
    	DateTime = "2019-03-15T09:00:00",  
    	TimeZone = "Pacific Standard Time"  
    };  
      
    var endTime = new DateTimeTimeZone  
    {  
    	DateTime = "2019-03-15T18:00:00",  
    	TimeZone = "Pacific Standard Time"  
    };  
      
    var availabilityViewInterval = 60;  
      
    await graphClient.Me.Calendar  
    	.GetSchedule(schedules,endTime,startTime,availabilityViewInterval)  
    	.Request()  
    	.Header("Prefer","outlook.timezone=\"Pacific Standard Time\"")  
    	.PostAsync();  
    

    You can find more details around this api here: https://learn.microsoft.com/en-us/graph/api/calendar-getschedule?view=graph-rest-1.0&tabs=csharp

    Hope this helps.

    Do let us know if this helps and if there are any more queries around this, please do let us know so that we can help you further. Also, please do not forget to accept the response as Answer; if the above response helped in answering your query.

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.