Using the MS Graph SDK, I want to retrieve scheduled calendar items for multiple users (acknowledging the max number of users with a single query is 20). However, I'm having difficulty understanding the structure of the RequestBuilder for this. Here's my code:
List<string> users = new List<String>()
{
"userA@tst.xyz",
"userB@tst.xyz"
};
ICalendarGetScheduleCollectionPage result = await graphClient
.Users["userA@tst.xyz"]
.Calendar
.GetSchedule(users, endTime, startTime, 15)
.Request()
.Header("Prefer", "outlook.timezone=\"Pacific/Auckland\"")
.PostAsync();
I seem to have to have a default user and include that in .Users["userA@tst.xyz"]
and then include them and all of the other users I want in my List<string> users
. Is that correct? That doesn't seem that logical to me which makes me suspect my understanding is incorrect.
Parameter in .User["user_principal"]
means you will execute the query in the name of that user, but it always makes no sense as you're using client credential. It only represents the oppisite of Me
here I think. There's a format in microsoft graph api, we usually query for someone's information by using .User["user_principal"]
, just useless in this scenario.
And for GetSchedule
, the user ids used here means this query will search for the availability information for these users.
===================================================
Pls refer to this document about the "getSchedule" feature.
POST /me/calendar/getSchedule
POST /users/{id|userPrincipalName}/calendar/getSchedule
You can see that this graph api provides 2 options, one for client.Me.Calendar
, and another is for client.User[userPrincipalName].Calendar
.
This means you can get the "GetSchedule" response with your own account(you get the credential in auth code/ROPC flow which needs you provide user information so that the credential can know who you are and can use "Me" in the request) or from a specific account(use e.g. clientcredential flow so that you have the permission to access all user via using User[userPrincipalName]).