Microsoft Graph: /sites?select=siteCollection,webUrl&filter=siteCollection/root%20ne%20null returns "Cannot enumerate sites" - microsoft-graph-api

Got error with call: /sites?select=siteCollection,webUrl&filter=siteCollection/root%20ne%20null
"error": {
"code": "invalidRequest",
"message": "Cannot enumerate sites",
"innerError": {
"request-id": "f73vvv65-d20e-xxx-ae30-829d46a981d6",
"date": "2019-10-24T17:17:03"
}
}

I strongly recommend you to go through this link. There is a typo with the request you are trying to make. $select and $filter are query options and hence, you'll have to use the following endpoint to obtain the desired result.
GET https://graph.microsoft.com/beta/sites?$select=siteCollection,webUrl&$filter=siteCollection/root%20ne%20null
Observe carefully that there is a $ sign before the filter query option.

Related

How to $filter appRoleAssignments based on appRoleId?

I have an enterprise application registered in Azure AD Tenant. It contains certain appRoles which have been assigned to Azure AD Users. Now, I would like to fetch all the users having some specific appRoles.
I have tried this:
GET /servicePrincipals/{id}/appRoleAssignedTo
taken from here:https://learn.microsoft.com/en-us/graph/api/serviceprincipal-list-approleassignedto?view=graph-rest-beta&tabs=http#optional-query-parameters
It seems like I am able to fetch all the appRoleAssignments successfully using this API, but whenever I put a filter such as: appRoleId eq {app-role-id} I am geting error like:
{
"error": {
"code": "Request_BadRequest",
"message": "Invalid filter clause appRoleId: System.Guid",
"innerError": {
"date": "2021-10-25T16:33:41",
"request-id": "{request-id}",
"client-request-id": "{client-request-id}"
}
}
}
And whenever I put single quotes, like appRoleId eq '{app-role-id}', I get this error:
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
"innerError": {
"date": "2021-10-25T16:34:30",
"request-id": "{request-id}",
"client-request-id": "{client-request-id}"
}
}
}
I tried with both v1 and beta endpoint. So how do I filter on appRoleId?
It seems that Microsoft Graph does not support the $filter on appRoleId yet. They already have an open issue:
https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/990
There is also a feature request here which we can upvote: https://techcommunity.microsoft.com/t5/microsoft-365-developer-platform/application-api-add-support-for-filtering-approleassignment-by/idi-p/2433822
Also in the Doc, $filter is only provided on principalDisplayName and resourceId
[1]: https://i.stack.imgur.com/ZVD8Y.png

"Cannot enumerate sites" while listing Sites with filter clause

I am stuck with a peculiar request and I'm not sure what/if I did something wrong.
I tries to call something like:
https://graph.microsoft.com/v1.0/sites?$filter=name eq 'Adele Vance'
where Adele Vance is a correct site name.
I end up with this error:
{
"error": {
"code": "invalidRequest",
"message": "Cannot enumerate sites",
"innerError": {
"date": "2021-07-27T16:37:12",
"request-id": "bebcc514-7e4e-4ffe-9987-4f1c9fd24f8e",
"client-request-id": "bebcc514-7e4e-4ffe-9987-4f1c9fd24f8e"
}
}
}
And I'm not quite sure why.
Has someone an idea ?
$filter clause is available only for Beta not v1.0.
You can use $search clause.
GET https://graph.microsoft.com/v1.0/sites?search="Adele Vance"

Function-specified Filter clause doesn't work for getting Sharepoint item list in Graph API

I'm trying to get a list of SharePoint items using Graph API with a Filter clause, but I get an error when I specify a function such as StartsWith.
The following page says, "Support for the $filter operator varies depending on the Microsoft Graph API. Commonly supported are the following logical operators." Is it possible to use them?
https://learn.microsoft.com/en-us/graph/query-parameters#filter-parameter
■In the case of eq, data can be retrieved
/sites/{site-id}/lists/{list-id}/items?$expand=fields&$filter=fields/Title eq 'test'
■In the case of startsWith, an error will occur saying it is an invalid filter clause.
/sites/{site-id}/lists/{list-id}/items?$expand=fields&$filter=fields/Title startsWith 'test'
ErrorMessage :
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
"innerError": {
"date": "2021-07-13T02:09:30",
"request-id": "5f84935b-59f1-46cf-a160-18d64e989eb7",
"client-request-id": "e417c442-123d-ba3b-1465-8ff7f4f78645"
}
}
}
You should specify startswith in your Graph API URL as :
$filter=startswith(fields/Title,'test')

How can i search MS Graph API for toRecipients

i am trying to to get email via graph APi based on the toRecipients . Is that posible or is it still only avail via search and not filter ?
I tried
https://graph.microsoft.com/beta/me/mailFolders('SentItems')/messages?$select=sender,subject,toRecipients&filter=(toRecipients/emailAddress/address) eq 'test#demo.com'
which generates the blow error.
{
"error": {
"code": "BadRequest",
"message": "Invalid filter clause",
"innerError": {
"request-id": "25583e87-66da-477b-a1be-0a0fd0371349",
"date": "2020-04-21T20:01:39"
}
}
}
i also tried To instead of toRecipients but that doesnt work eithet.
Can you try the following? Note the $filter query parameter.
https://graph.microsoft.com/beta/me/mailFolders('SentItems')/messages?$select=sender,subject,toRecipients&$filter=(toRecipients/emailAddress/address) eq 'test#demo.com'

$filter "not groupTypes/any() " on Groups in Microsoft Graph

The following works in Graph Explorer:
https://graph.microsoft.com/v1.0/groups?$filter=groupTypes/any(c:c eq 'Unified')
However, this does not:
https://graph.microsoft.com/v1.0/groups?$filter=not groupTypes/any()
This returns
{
"error": {
"code": "BadRequest",
"message": "Filter not supported.",
"innerError": {
"request-id": "d0c9fac3-9ee4-4b92-8841-6dbefca2d150",
"date": "2017-07-20T13:37:18"
}
}
}
Am I constructing the OData $filter the wrong way or is it really not supported? (use case: give me all groups except unified ones)
The verb not isn't recognized by Graph. I expect what you're looking for here would be ne such as:
https://graph.microsoft.com/v1.0/groups?$filter=groupTypes/any(c:c ne 'Unified')
You can read about the $filter parameter in the Graph Documentation.
https://graph.microsoft.com/v1.0/me/memberOf/$/microsoft.graph.group?$filter=groupTypes/any(a:a%20eq%20'unified')
You can read about it in Documentation - Reference https://learn.microsoft.com/en-us/graph/overview

Resources