Plai
Plai

Reputation: 21

Filtering by file type or name in Microsoft Graph API

If I want to find just image files using the Microsoft Graph API. Is there a way to filter using $filter? By file type or name "endswith"?

I try

https://graph.microsoft.com/v1.0/sites/{MyID}.sharepoint.com/lists/{Drive ID}/items?$filter=endswith(webUrl, '.png')

but got this error

"message": "Item not found",

but there is an image (.png) file contain in the drive , My goal is to get response all of image file that contain in Drive in Sharepoint

Upvotes: 0

Views: 2350

Answers (1)

Shiva Keshav Varma
Shiva Keshav Varma

Reputation: 3575

Yeah, I agree that there is no name property populated in the response even if its documented here that there is a name property. And all properties doesn't support all ODATA query parameters as far as I know.

But you can do one thing. There is a fields relationship which you can use to get the filename with extension. Use the query below.

https://graph.microsoft.com/v1.0/sites/soaadteam.sharepoint.com/lists/8f7fc3c2-8d9b-4563-94c8-b63bf0f19ebc/items?$expand=fields

Pick that LinkFilename property from fields property and you can filter it on your end(by writing code) easily.

enter image description here

Upvotes: 1

Related Questions