Reputation: 51
To filter Microsoft Graph API responses, the docs suggest to use the filter
query option.
Here I've used startswith
and endswith
string functions on the '/me/messages'
endpoint.
query = {
'$filter': "
startswith(from/emailAddress/address, 'abcd')
or endswith(from/emailAddress/address, 'gmail.com')"
}
Only using startswith
returns the expected response. On adding the endswith
function to the filter query, the response received is an error.
{
"error": {
"code": "ErrorInvalidUrlQueryFilter",
"message": "The query filter contains one or more invalid nodes.",
"innerError": {
"request-id": "0d12e1f6-6105-4826-9656-8613f8c167ed",
"date": "2019-03-14T11:05:56"
}
}
}
Upvotes: 5
Views: 8108
Reputation: 53
Microsoft Graph has a tricky set of API endpoints. "endswith" works only with the "mail" field, not others. "startswith" works with almost all the fields. "contains" doesn't work at all.
Alternatively, you can use $search, which might some extra features
Upvotes: 2
Reputation: 3716
Copied this exact same query (with the ConsistencyLevel either in the query params or headers params and wasn't able to make it work. The app that I used to request authorisation token have Users.ReadWrite.All permission AND the User.Read.All.
In Postman :
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported property filter clause operator 'SuffixMatch'.",
"innerError": {
"date": "2022-07-27T13:22:38",
"request-id": "3f509514-4e77-4eb1-8557-0fe102d502f5",
"client-request-id": "3f509514-4e77-4eb1-8557-0fe102d502f5"
}
}
}
----- EDIT ------
Just found my answer here : https://learn.microsoft.com/en-us/graph/query-parameters
Use of $count is not supported in Azure AD B2C tenants.
Upvotes: 0
Reputation: 91
To use $filter with endsWith you need to:
Example : 'https://graph.microsoft.com/v1.0/users?$count=true&ConsistencyLevel=eventual&$filter=endswith(mail,'@hotmail.com')'
**It works for mail and userPrincipalName but not for displayName
Upvotes: 6