How can i search MS Graph API for toRecipients - microsoft-graph-api

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'

Related

Microsoft Graph API - $filter email address by domain

As Title, I try to filter my email by domain. But got a error message "ErrorInvalidUrlQueryFilter". How can I do?
API query:
https://graph.microsoft.com/v1.0/me/messages?$filter=endswith(from/emailAddress/address,'#xxx.com')
Response:
{
"error": {
"code": "ErrorInvalidUrlQueryFilter",
"message": "The query filter contains one or more invalid nodes.",
"innerError": {
"date": "2023-02-03T08:59:37",
"request-id": "b3a28220-91d1-40b5-a34a-10cc73069951",
"client-request-id": "74043780-6e6b-dc63-5434-0ac03412b3ca"
}
}
}
endsWith operator is not supported for filtering messages by from/emailAddress/address.
As a workaround you can use contains. It will have the same affect for email address as using endsWith if you will filter by #domain.
GET https://graph.microsoft.com/v1.0/me/messages?$filter=contains(from/emailAddress/address,'#xxx.com')

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

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

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.

Microsoft Graph API - Unable to filter with endswith

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"
}
}
}
To use $filter with endsWith you need to:
Add $count=true to the query parameters
Add ConsistencyLevel: eventual request header
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
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 :
GET https://graph.microsoft.com/v1.0/users?$count=true&ConsistencyLevel=eventual&$filter=endswith(mail,'#hotmail.com')
{
"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.

$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