How to retrieve the events from Calendar when using the $expend parameter in MS Graph API? - microsoft-graph-api

I want to get the events in the a specific user's calendar by using the MS Graph API. I have used the API GET https://graph.microsoft.com/v1.0/me/calendars?$expend=events, However, it does not work. The events collection is null. And there are some event in my calendar.
Anyone can help?

According to your description, I assume you want to list the events in a specific user's calendar.
Based on my test, we can use the following code:
public async Task<ICollection<Event>> EventsAsync(string calendarId)
{
var events = await _serviceClient.Me.Calendars[calendarId].Events.Request().GetAsync();
return events.CurrentPage;
}
As the event is a relationships of the calendar, so the event will be null when we request a calendar. However, according to this document:
Note: Not all relationships and resources support the $expand query parameter. For example, you can expand the directReports, manager, and memberOf relationships on a user, but you cannot expand its events, messages, or photo relationships. Not all resources or relationships support using $select on expanded items
So we need request the GET /users/{id | userPrincipalName}/calendars/{id}/eventsendpoint

Related

MS Graph API - how to retrieve declined events?

Let's say person B sends a calendar event invite to person A. When we then run the following query for person A, we can see the event in the response with responseStatus.response="notResponded", which is fine:
https://graph.microsoft.com/v1.0/me/events?startDateTime=2023-01-11T23%3A00%3A01.000Z&endDateTime=2023-01-12T23%3A00%3A00.000Z
However, when person A declines the invitation, then the event disappears from the response.
Is there a way to modify the query or use a different endpoint to still have access to the declined events?
I tried to look for the solution in the MS Graph API docs, but couldn't find any hints.
responseStatus property doesn't support filtering but as an alternative you can use extended property PidLidResponseStatus and filter those events with PidLidResponseStatus equals to respDeclined int value 4.
https://graph.microsoft.com/v1.0/me/events?startDateTime=2023-01-11T23%3A00%3A01.000Z&endDateTime=2023-01-12T23%3A00%3A00.000Z&$filter=singleValueExtendedProperties/any(ep:ep/id eq 'Integer {00062002-0000-0000-C000-000000000046} Id 0x8218' and cast(ep/value, Edm.Int32) eq 4)
But if declined event is remove from the calendar then it cannot be listed.
Documentation:
PidLidResponseStatus

MS Graph: Get all users by manager id

I'm trying to gather all users with a given manager's id.
It seems that MS graph has a bug here.
My query:
https://graph.microsoft.com/v1.0/users?$filter=manager/id eq '0f3b8a2f-8bec-4694-8021-dbfc55eed287'
I expect this query to return all the users that belong to the manager with the given id.
However, this query returns the manager and not the users. But I clearly filter the id of the manager related property and not the user's id.
There's an API specifically for this, List directReports.
You can get the users assigned to the manager with id 0f3b8a2f-8bec-4694-8021-dbfc55eed287 like:
GET /users/0f3b8a2f-8bec-4694-8021-dbfc55eed287/directReports
Another way would be
GET /users/0f3b8a2f-8bec-4694-8021-dbfa55eed297?$expand=directReports

Does Microsoft Graph have lastModifiedDateTime to detect latest entity changes?

Some of the Graph API return a lot of data and require paging. Exists a lastModifiedDateTime property to get only changed rows, such as to make this call that returns users who are modified since a given date?
https://graph.microsoft.com/beta/users?$filter=lastModifiedDateTime gt '2020-01-01T12:00:00Z'
or get the classes that have changed (Educational API)
https://graph.microsoft.com/beta/education/classes?$filter=lastModifiedDateTime gt '2020-01-01T12:00:00Z'
The Property you are trying i.e., 'lastModifiedDateTime' is not part of the MS Graph.
In Ms Graph this is possible with directoryAudits method which contains all information related to changes(logs) in Azure AD.
To Get the last activity in azure you need to use 'activityDateTime' property and to get the user information 'initiatedBy' property.

Unable to expand MemberOf using Microsoft Graph .NET SDK using Delta Query

Expanding properties doesn't seem to work when using Delta queries. It works fine with regular user query.
Is this a limitation in Microsoft Graph API?
var usersInfo = graphServiceClientWithApplicationPermission.Users.Delta().Request().Expand("MemberOf").GetAsync();
// Add inital request users
foreach (var userInfo in usersInfo)
{
// Member info doesn't seem to be expanded even if $expand=MemberOf is sent
if (userInfo.MemberOf == null)
{
userInfo.MemberOf = await applicationPermissionsClient.Users[userInfo.Id].MemberOf.Request().GetAsync();
}
// MemberOf is now populated ??
}
Seems like this is another limitation of the Microsoft Graph and not supported.
Optional query parameters
If a client uses a query parameter, it must be specified in the
initial request. Microsoft Graph automatically encodes the specified
parameter into the nextLink or deltaLink provided in the response. The
calling application only needs to specify their desired query
parameters once upfront. Microsoft Graph adds the specified parameters
automatically for all subsequent requests. For users and groups, t
here are restrictions on using some query parameters:
If a $select query parameter is used, the parameter indicates that the
client prefers to only track changes on the properties or
relationships specified in the $select statement. If a change occurs
to a property that is not selected, the resource for which that
property changed does not appear in the delta response after a
subsequent request. $expand is not supported.
For users and groups beta (preview) APIs, scoping filters allow you to
track changes to one or more specific users or groups by objectId. For
example, the following request:
https://graph.microsoft.com/beta/groups/delta/?$filter= id eq
'477e9fc6-5de7-4406-bb2a-7e5c83c9ae5f' or id eq
'004d6a07-fe70-4b92-add5-e6e37b8acd8e' returns changes for the groups
matching the ids specified in the query filter.
https://developer.microsoft.com/en-us/graph/docs/concepts/delta_query_overview

Microsoft graph API: finding event by iCalUid

I would like to decline one instance of recurring meeting. I only have masterSerieId, iCalId, time of that instance.
Do you know how I could cancel that instance?
Do I have to query using masterId and time of the instance to find event id or there is a way I would just find eventId using iCalId?
You can use OData query options to filter on just the event that has that particular iCalUId.
For instance:
GET https://graph.microsoft.com/v1.0/me/events?$filter=iCalUId eq '<your iCalUId>'
Sadly the calendar view endpoint does not include events which are part of an event series if you match against a given iCalUId.
So if an event has a seriesMasterId which is not null, you wont find it by filtering for the iCalUId.

Resources