My requirement is to get only the document library list of SharePoint via Rest API.
I added Files.ReadWrite.All application permission and got token with scope: https://graph.microsoft.com/.default
To filter only document library of SharePoint, I'm using this:
GET https://graph.microsoft.com/v1.0/sites/siteid/drives?$filter=(driveType eq "documentLibrary")
This threw me "400 Bad Request". I have no idea why I am getting this error. The complete error looks like:
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
}
}
Did anyone face the same scenario? I am totally confused. How to get rid of it? How to add filters in the Graph api query?
I tried to reproduce same in my environment and got below results:
I created one Azure AD application and granted API permission like below:
I got the access token via Postman with same scope as below:
POST https://login.microsoftonline.com/<tenant_id>/oauth2/v2.0/token
client_id: client_id
grant_type:client_credentials
client_secret: client_secret
scope:https://graph.microsoft.com/.default
Response:
When I used the above token to call below query, I got the same error as you:
GET https://graph.microsoft.com/v1.0/sites/<siteID>/drives?$filter=(driveType eq "documentLibrary")
Response:
To resolve the error, try modifying your filter query like below:
GET https://graph.microsoft.com/v1.0/sites/<siteID>/drives?$filter=driveType eq 'documentLibrary' &$select=id,createdDateTime,name,webUrl,driveType
Response: