OData query for the SharePoint API

Viewed 50

I am trying to filter the recourses the I receive from calling the SharePoint API and I run into a problem of how to filter the data based on child elements.

EX: I only want the items that contain Audience eq Agent.

</author>
<content type="application/xml">
<m:properties>
<d:FileSystemObjectType m:type="Edm.Int32">0</d:FileSystemObjectType>
<d:Id m:type="Edm.Int32">4</d:Id>
<d:ServerRedirectedEmbedUri m:null="true"/>
<d:ServerRedirectedEmbedUrl/>
<d:ContentTypeId>0x010100D45EB268542352489AC34E7F5EF7798B</d:ContentTypeId>
<d:ComplianceAssetId m:null="true"/>
<d:Title m:null="true"/>
<d:OData__dlc_DocId>4PXE6S6DFQCP-354194108-4</d:OData__dlc_DocId>
<d:OData__dlc_DocIdUrl m:type="SP.FieldUrlValue">
<d:Description>4PXE6S6DFQCP-354194108-4</d:Description>
</d:OData__dlc_DocIdUrl>

<d:Audience m:type="Collection(Edm.String)">
<d:element>Agent</d:element>
<d:element>Internal</d:element>
<d:element>Insured</d:element>
</d:Audience>

<d:ID m:type="Edm.Int32">4</d:ID>
<d:Created m:type="Edm.DateTime">2022-05-05T19:21:54Z</d:Created>
<d:AuthorId m:type="Edm.Int32">1204</d:AuthorId>
<d:Modified m:type="Edm.DateTime">2022-05-05T19:25:29Z</d:Modified>
<d:EditorId m:type="Edm.Int32">1204</d:EditorId>
<d:OData__CopySource m:null="true"/>
<d:CheckoutUserId m:null="true"/>
<d:OData__UIVersionString>3.0</d:OData__UIVersionString>
<d:GUID m:type="Edm.Guid">cdcd1fed-f0e3-4bb7-9074-2bf8dfb40e53</d:GUID>
</m:properties>
</content>  

Question: How would I filter on child elements using OData? ($filter=Audience/ eq "Agent")?

1 Answers

You need to use any operator because Audience is a collection.

$filter=Audience/any(a:a eq 'Agent'))

Resources:

any operator

Related