Expanded SingleValueExtendedProperties do not show up when combined with $select - microsoft-graph-api

I'm currently using Microsoft Graph to retrieve appointments from a users calendar. I need to access the singleValueExtendedProperties and only a few properties of the appointment.
Accessing this url
https://graph.microsoft.com/v1.0/users/XXXXXX/calendarView?startDateTime=2023-05-01T12:00:00&endDateTime=2023-05-30T12:00:00&$expand=singleValueExtendedProperties($filter=id eq 'String {GUID1} Name Creator' or id eq 'String {GUID2} Name Type')&$top=50
returns the entire appointments with it's singleValueExtendeProperties.
However, when I combine that with a select like so
https://graph.microsoft.com/v1.0/users/XXXXXX/calendarView?startDateTime=2023-05-01T12:00:00&endDateTime=2023-05-30T12:00:00&$expand=singleValueExtendedProperties($filter=id eq 'String {GUID1} Name Creator' or id eq 'String {GUID2} Name Type')&$select=id,start,end,isAllDay,showAs,categories,subject,sensitivity,singleValueExtendedProperties&$top=50
I only get the selected fields without the singleValueExtendedProperties.
Am I doing something wrong?

This is a known issue/bug with the Graph Microsoft Graph -> Use the singleValueExtendedProperty in OData $select when expanded $expand one way of working around it is to include the extendedproperty you want returned in a filter clause, even though you may not want to filter items you can make your filter generic so it just returns all item with that property eg this is an example just using the extended property for subject (note your shouldn't have
https://graph.microsoft.com/v1.0/me/calendar/calendarView?startDateTime=2022-09-01T19:00:00Z&endDateTime=2022-09-10T19:00:00Z&$select=Subject,Start,End,singleValueExtendedProperties&$expand=singleValueExtendedProperties($filter=id eq 'String 0x0037')&$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String 0x0037' and ep/value ne null)
IMO Microsoft should just fix this on the backend.

Related

How to incorporate the usage of AND when querying onPremisesExtensionAttributes/extensionAttribute in the MS Graph API?

I'm currently trying to query multiple values when it comes to onPremisesExtensionAttributes/extensionAttribute in MS Graph API.
I'm able to query this one:
https://graph.microsoft.com/beta/users?$count=true&$filter=onPremisesExtensionAttributes/extensionAttribute1 eq 'attr1'
But I want to query more values than attr1, but I haven't managed to get it to work.
I've tried queries, such as these two:
https://graph.microsoft.com/beta/users?$count=true&$filter=onPremisesExtensionAttributes/extensionAttribute1 eq 'attr1' and 'attr2' and 'attr3'
https://graph.microsoft.com/beta/users?$count=true&$filter=onPremisesExtensionAttributes/extensionAttribute13 eq 'attr1'&$onPremisesExtensionAttributes/extensionAttribute1 eq 'attr2'&$onPremisesExtensionAttributes/extensionAttribute1 eq 'attr3'
the correct syntax should be
$filter=onPremisesExtensionAttributes/extensionAttribute13 eq 'attr1' and onPremisesExtensionAttributes/extensionAttribute13 eq 'attr2' and onPremisesExtensionAttributes/extensionAttribute13 eq 'attr3'
one filter param to include all conditions, and each condition is full - field eq 'value'

Filter SharePoint library items by lookup column using Graph API

I have a SharePoint list and a document library. Each document is linked to an item in my list using a custom field CustomRecordLookupId
If I select all documents and use $expand=listitem, I can see the CustomRecordLookupId values in the results.
I am unable to use this lookup column to query, however.
https://graph.microsoft.com/v1.0/drives/{drive_id}/root/children?$expand=listitem&$filter=listitem/fields/CustomRecordLookupId eq 1
The error is: Operation not supported
Per my test, I got the same result as yours. This is not supported for drive item, you should do the filter for listitems:
https://graph.microsoft.com/v1.0/sites/{site_id}/lists/{list_id}/items?$expand=fields&$filter=fields/CustomRecordLookupId eq 1

OData Filter by an M-M relationship

Is it possible to filter in odata by the linked entities in an M-M relationship where it must contain all of the second, but allow extras?
Suppose I've got:
Student
StudentClass
Class
and I want to find all students where their enrolment includes the classes (101, 102, 103)
Yes, OData v4 provides 2 Lambda Operators that evaluate a Boolean expression on a collection. These are Any and All, where Any returns the record if atleast one of the child entries matches the criteria, and All requires all of the child records to match.
In your case we can use Any:
5.1.1.10.1 any
The any operator applies a Boolean expression to each member of a collection and returns true if the expression is true for any member of the collection, otherwise it returns false. The any operator without an argument returns true if the collection is not empty.
Example 79: all Orders that have any Items with a Quantity greater than 100
http://host/service/Orders?$filter=Items/any(d:d/Quantity gt 100)
however we can't pass through an array or list of values to compare against so we have to break this query down into an Any expression for each value and AND them together.
This sounds counter intuitive but the following simple query where we use OR inside a single Any results in matches where the Student has one or more of the classes (101,102,103) but not neccessarily all of them:
http://host/service/Students?$filter=Enrollments/Any(e:e/Class/Code eq '101' or e/Class/Code eq '102' or e/Class/Code eq '103')
if they must be enrolled in atleast all of 101,102,103 then we must AND the results of a separate Any operator for each of the classes, below is the 3 separate queries for each class and a final query that ANDs them together:
http://host/service/Students?$filter=Enrollments/Any(e:e/Class/Code eq '101')
http://host/service/Students?$filter=Enrollments/Any(e:e/Class/Code eq '102')
http://host/service/Students?$filter=Enrollments/Any(e:e/Class/Code eq '103')
http://host/service/Students?$filter=Enrollments/Any(e:e/Class/Code eq '101') AND Enrollments/Any(e:e/Class/Code eq '102') AND Enrollments/Any(e:e/Class/Code eq '103')
These queries assume:
there is a navigation property on the Student record called Enrollments that links the Student to a collection of StudentClass records,
StudentClass has a navigation property called 'Class' that links it to a single Class record,
the class codes (101,102,103) are stored in a string property on the Class record called Code
NOTE: Different providers support these Lambda operators to different extents, you should check with your vendor/developer if you have have complex needs like support for nesting expressions with Any or All or if the simplest queries are not resolving as you expect.
This query does not specifically request that the Enrollments or the Class records be included in the results, it should only return a list of Students unless there is server-side configuration or logic to $expand these navigation properties by default.
While not needed by OP, if you are expanding these same object graphs (that you are filtering by), it is important to point out that using the Any operator in the root $filter query option will not apply filtering to the expanded child collection. If you wanted to return ONLY the child records that matched the expression you would need to implement a $filter expression within the $expand query option, in addition to the Any operator in the root $filter query option.
The reverse is also true, simply using the $filter within the $expand query option will not prevent the top level Student from being returned if they were only enrolled in other classes, it wouldn't return any classes because they didn't match the criteria, but it would still return the Student record.
For this reason, when using $filter nested inside $expand it is very common to include an Any or All operator in the $filter query option.

How to get EndRecurrenceDate using microsoft graph api

I am trying to get EndRecurrenceDate using ms graph api by referring this documents .link 1
none of followings didn't work for me . what could be the reasons
https://graph.microsoft.com/v1.0/me/events/{event-id}==?$expand=singleValueExtendedProperties($filter=id eq 'String {6ED8DA90-450B-101B-98DA-00AA003F1305} Id 0x0000000F')
.
I chnaged expand query but it also does not give any value for singleValueExtendedProperties in API response
$expand=singleValueExtendedProperties($filter=id eq 'Date {6ED8DA90-450B-101B-98DA-00AA003F1305} Id 0x0000000F')
$expand=singleValueExtendedProperties($filter=id eq 'String {6ED8DA90-450B-101B-98DA-00AA003F1305} Id 0x0000000F')
$expand=singleValueExtendedProperties($filter=id eq 'String {6ED8DA90-450B-101B-98DA-00AA003F1305} Name PidLidEndRecurrenceTime')
In MS-Graph API, please retrieve the seriesMaster by passing the seriesMasterId corresponding to the given event:
https://learn.microsoft.com/en-us/graph/api/resources/event?view=graph-rest-1.0
For verification, please check the field "type" which specifies the event type. It should have value "seriesMaster".
In the seriesMaster that has been retrieved, the field "end" will represent the end date of the recurrence.

OData filter options (handle null or empty values)

We are using $filter system query option in OData to execute filters where the filter value is sent in at runtime.
As an example the OData URL would be like this:
http://services.odata.org/Northwind/Northwind.svc/Customers?$filter=CustomerID eq #InCustomerID and Country eq #InCountry
where #InCustomerID & #InCountry are the input values for the equal filter.
At run time when the user enters some value for Customer ID (say 'ABCD') we would replace the #InCustomerID by 'ABCD'
At runtime the query would be as follows:
http://services.odata.org/Northwind/Northwind.svc/Customers?$filter=CustomerID eq 'ABCD' and Country eq 'US'
In the above case the user has entered the following values: CustomerID => 'ABCD' and Country => 'US'
My question is regarding handling of null values in OData $filter. If the user does not enter any value for CustomerID then we want to select all customers from specific country.
In sql case this would be something like:
select * from Customers where ((CustomerID = #InCustomerID) or (#CustomerID is null)) and (Country = #Country).
Essentially how to handle null or empty values so that the specific predicate in the logical condition would always be true.
Does OData filtering enables this option?
You can compare to null using the equality operator like this:
$filter=CustomerID eq null
In your case the query would degenerate to something like:
$filter=(CustomerID eq null) or (null eq null)
Which should work, but it's not very nice.
Did you consider removing the predicate completely in such case?

Resources