I am trying to run:
https://graph.microsoft.com/beta/users?$filter=startsWith(officeLocation, 'MOD')
and according to Microsoft Docs user resource type:
officeLocation String
Supports $filter (eq, ne, not, ge, le, in, startsWith, and eq on null values).
However, the response I am getting is:
"error": { "code": "Request_UnsupportedQuery", "message": "Unsupported or invalid query filter clause specified for property 'officeLocation' of resource 'User'.",
What am I missing or doing wrong?
Try to add query parameter $count=true and header ConsistencyLevel:eventual.
https://graph.microsoft.com/beta/users?$filter=startsWith(officeLocation, 'MOD')&$count=true
Advanced query capabilities on Azure AD directory objects
Related
I am trying to simplify a GraphAPI request to get a list of mail folders based on a displayName filter. This seems to work with the eq operator but not with in. Below are the two requests, which should return the same result.
Using eq:
https://graph.microsoft.com/v1.0/me/mailfolders?$filter=displayName eq 'inbox' or displayName eq 'drafts'
Using in:
https://graph.microsoft.com/v1.0/me/mailfolders?$filter=displayName in ('inbox', 'drafts')
When using in I get the error below:
{
"error": {
"code": "ErrorInvalidUrlQueryFilter",
"message": "The query filter contains one or more invalid nodes.",
"innerError": {
"date": "2022-02-16T16:48:51",
"request-id": "",
"client-request-id": ""
}
}
}
From the documentation I've read in should be supported wherever eq is supported by default. Syntax should be correct based on examples I found here: https://learn.microsoft.com/en-us/graph/query-parameters#examples-using-the-filter-query-operator
Can someone shed some light on what the issue might be?
Your last statement applies only to directory objects (resources that are documented as inheriting from the directoryObject resource.
mailFolder isn't one of them
for inbox for example, you can use directly this:
https://graph.microsoft.com/v1.0/me/mailFolders/Inbox
Source: https://learn.microsoft.com/en-us/graph/api/resources/mailfolder?view=graph-rest-1.0
According to the MS Graph API documentation, businessPhones are supported to be used in a $filter query with eq comparison, just like the imAddresses property.
When inspecting Microsoft's use query parameters documentation, there's an example where the imAddresses property is used in a collection filter and it works just fine.
GET https://graph.microsoft.com/v1.0/users?$filter=imAddresses/any(s:s eq 'admin#contoso.com')
My goal ist to list all users that have a specific phone number in their businessPhones collection property.
However, when I try to use the businessPhones property in a similar query, the query does not work as expected.
GET https://graph.microsoft.com/v1.0/users?$filter=businessPhones/any(s:s eq '1234')
Status code: 400
{
"error": {
"code": "Request_UnsupportedQuery",
"message": "Unsupported or invalid query filter clause specified for property 'businessPhones' of resource 'User'.",
"innerError": {
"date": "2021-07-30T08:07:24",
"request-id": "ac3923be-de11-448f-b2b5-245edc82d20e",
"client-request-id": "ac3923be-de11-448f-b2b5-245edc82d20e"
}
}
}
Any ideas on what I am missing?
You need to use advanced query capabilities, which means you need to add a $count=true query string parameter and a ConsistencyLevel=Eventual header to your request.
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')
I'm trying to $expand on singleValueExtendedProperties for a delta query on my messages, but I'm getting an odd error.
Delta query
https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages/delta?$expand=singleValueExtendedProperties($filter=id eq 'String 0x007D')
Response
{
"error": {
"code": "InternalServerError",
"message": "Value cannot be null.\r\nParameter name: type",
"innerError": {
"request-id": "d7cf6c83-a062-4051-85b4-30a5aadf2e65",
"date": "2017-10-06T10:05:10"
}
}
}
The documentation says this is supported. I've also verified (via the GraphAPI explorer) that:
the non-delta version of the query works with singleValueExtendedProperties
the delta version works without singleValueExtendedProperties
Is this a bug in the API or expected behavior? I know I can follow up with multiples GETs to pull the desired extended properties, but I'd rather avoid spawning several requests if I can get away with one.
There is limited support for the $filter query parameter on messages/delta. From the documentation:
The only supported $filter expresssions are $filter=receivedDateTime+ge+{value} or $filter=receivedDateTime+gt+{value}.
What is the query to get emails received from a specific sender email address?
I have tried filtering on the "Address" property of the "From" property, which is a "Recipient" complex type according to O365 Microsoft.Exchange.Services.OData.Model namespace.
OData filtering on complex types goes something like this
/Me/Inbox/Messages?$filter=From/Address eq 'email#email.com'
However, this returns the following error:
"error": {
"code": "ErrorInvalidProperty",
"message": "The property 'Address' is invalid.",
"innererror": {
"message": "The property 'Address' is invalid.",
"type": "Microsoft.Exchange.Services.OData.InvalidPropertyException",
"stacktrace": " at Microsoft.Exchange.Services.OData.SchemaExtensions.ResolveProperty(Schema schema, String propertyName)\r\n at Microsoft.Exchange.Services.OData.Model.EwsFilterConverter.GetPropertyProvider(QueryNode queryNode)\r\n at Microsoft.Exchange.Services.OData.Model.EwsFilterConverter.ConvertFilterNode(QueryNode queryNode)\r\n at Microsoft.Exchange.Services.OData.Model.EwsQueryAdapter.GetRestriction()\r\n at Microsoft.Exchange.Services.OData.Model.MessageProvider.Find(String parentFolderId, MessageQueryAdapter queryAdapter)\r\n at Microsoft.Exchange.Services.OData.Model.FindMessagesCommand.InternalExecute()\r\n at Microsoft.Exchange.Services.OData.ODataCommand`2.Execute()\r\n at Microsoft.Exchange.Services.OData.ODataTask.Execute(TimeSpan queueAndDelayTime, TimeSpan totalTime)"
}
}
I got the same error that property of complex type is invalid.
It seems that exchange service does not support complex type filtering.
You can try getting all the Messages to local storage and doing filtering.
Email address is a complex type however it is listed as filterable (https://msdn.microsoft.com/office/office365/APi/complex-types-for-mail-contacts-calendar#RESTAPIResourcesMessage) which means the following should work...
https://outlook.office365.com/api/v1.0/me/messages?$filter=From/EmailAddress/Address eq 'email#email.com'
However, I'm having trouble with this, it seems to be simply returning blank values whereas the following works...
https://outlook.office365.com/api/v1.0/me/messages?$filter=From/EmailAddress/Name eq 'Joe Bloggs'
So, there could be a fault with the API or the email address might need to be formatted differently.