Forum Discussion
NShivaBarath
Jan 08, 2023Copper Contributor
Issue in formulating the Filter for SharePoint using Microsoft Graph API
I am trying to use the filter to get all the Folders within a specific Document Library.
The following throws error saying that
Microsoft.Graph.ServiceException
HResult=0x80131500
Message=Code: BadRequest
Message: Invalid filter clause
var taskSearch = graphClient.Sites[site.Id].Lists["NameOfDocumentlibrary"].Items.Request().Filter("ContentType/any(i:i/Name eq Folder").GetAsync();
var searchResult = taskSearch.GetAwaiter().GetResult();
The following returns all the items within the Document Library without any error:
var taskSearch = graphClient.Sites[site.Id].Lists["NameOfTheDocumentLibrary"].Items.Request().GetAsync();
Please advise on this.
Thanks
- SvenSieverdingBronze Contributor
Hi NShivaBarath,
i normally use the "FSObjType" in the filter if i want to select foldersvar taskSearch = graphClient.Sites[site.Id].Lists["NameOfDocumentlibrary"].Items.Request().Filter("FSObjType eq 1").GetAsync();
I like it more, because it does not depend on the folder content type to be named "Folder".
See more documentation here: "https://learn.microsoft.com/en-us/previous-versions/office/sharepoint-csom/ee537053(v=office.15)"
I think you are missing a ")" somewhere in your query.
Best Regards,Sven