Our goal here is to get the emails of the specific users within a specific received date time and lists only the following mail properties:
from, toRecipients, ccRecipients, bccRecipients
Here's the query that we ran
https://graph.microsoft.com/v1.0/users/user1#contoso.com/messages$select=from,toRecipients,ccRecipients,bccRecipients$filter=ReceivedDateTime ge 2019-07-01 and receivedDate lt 2019-07-02
https://graph.microsoft.com/v1.0/users/user1#contoso.com/messages$select=from,toRecipients,ccRecipients,bccRecipients$filter=ReceivedDateTime ge 2019-07-01 and receivedDate lt 2019-07-02
Error:
{
"error": {
"code": "ErrorFolderNotFound",
"message": "The specified folder could not be found in the store.",
"innerError": {
"request-id": "8b58633d-3e7f-4e25-a6bc-bd1562340bc4",
"date": "2019-07-30T15:11:12"
}
}
}
Your query link has a couple mistakes in it:
Since $select and $filter attributes are a part of the URL query string, they must be preceded by ?
$filter is a separate parameter from $select, so they must be separated by &
The selected/filtered attributes must match exactly to what the API supplies, including case (you wrote "ReceivedDateTime" and "receivedDate", both of which should be "receivedDateTime"
Here is the corrected URL:
https://graph.microsoft.com/v1.0/users/user1#contoso.com/messages?$select=from,toRecipients,ccRecipients,bccRecipients&$filter=receivedDateTime ge 2019-07-01 and receivedDateTime lt 2019-07-02
For a list of all mail properties available, see the documentation
Related
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
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.
trying to add extended properties to calendar objects. I am able to create calendars with the following payload (Ruby syntax, payload is sent as a JSON):
name: build_calendar_name,
singleValueExtendedProperties: [{
id: "String {#{SecureRandom.uuid}} Name setting_id",
value: #setting_id.to_s
}]
I receive a 201 from this request and the calendar is created no problem
The frustrating part is I cannot retrieve the extended property when making a GET request. The following two requests should work:
GET /me/events/calendar_id?$expand=singleValueExtendedProperties($filter=id eq 'String {guuid} Name setting_id')
Response
{
"error": {
"code": "BadRequest",
"message": "Parsing OData Select and Expand failed: Found an unbalanced bracket expression.",
"innerError": {
"date": "2020-07-01T22:38:14",
"request-id": "<hidden>"
}
}
}
GET /me/calendars?$filter=singleValueExtendedProperties/Any(ep: ep/id eq 'String {guuid} Name setting_id' and ep/value eq 'setting_id')
Response:
{
"error": {
"code": "ErrorInternalServerError",
"message": "An internal server error occurred. The operation failed.",
"innerError": {
"date": "2020-07-01T22:40:15",
"request-id": "<hidden>"
}
}
}
Guuid, calendar_id and setting_id are dummy values, real values are used when attempting these calls.
We've also tried following the examples verbatim at this link https://learn.microsoft.com/en-us/graph/api/singlevaluelegacyextendedproperty-get?view=graph-rest-1.0&tabs=http#example and still receive these response codes. Would love some help with this. Thanks!
I reproduced this for the $expand case in Graph Explorer. The problem seems to be the = inside the parentheses. If you URL-encode that to %3D the query works fine.
$expand=singleValueExtendedProperties($filter%3Did eq 'String {guuid} Name setting_id')
For the $filter, I reproduce it when doing GET /me/calendars, but not when doing GET /me/events. This seems to be a problem with the service (unless the docs are just wrong). Let me check and report back.
This question is a follow-up to Get custom property set in Outlook Add-In via Microsoft Graph.
My Outlook Office.js add-in is adding some custom properties to an event. It works as expected and I can access those properties using Microsoft Graph, with following GET request:
/v1.0/me/events/{event-id}?$expand=SingleValueExtendedProperties($filter=id%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af')
But now I try to subscribe to push notifications by posting such body to the push notifications endpoint (/v1.0/subscriptions):
{
changeType: "created,updated,deleted",
notificationUrl: `[...my url...]`,
resource: `/users/${userData.id}/events?$filter=singleValueExtendedProperties/any(ep%3A%20ep%2Fid%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af')`,
expirationDateTime: tomorrow,
clientState: "SecretClientState"
}
But I'm getting:
{
"error": {
"code": "ExtensionError",
"message": "Operation: Create; Exception: [Status Code: BadRequest; Reason: Bad Request]",
"innerError": {
"request-id": "01dcece6-0103-4bef-8231-e9ab9480402a",
"date": "2017-04-04T20:20:58"
}
}
}
Tried to set the resource in the request unescaped, but with same result, next thing I tried is the $filter functionality, so did a get request in following format using the MS Graph explorer:
/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep%3A%20ep%2Fid%20eq%20'String%20{00020329-0000-0000-C000-000000000046}%20Name%20cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af')
but got following error:
{
"error": {
"code": "ErrorInvalidUrlQueryFilter",
"message": "The filter expression for $filter does not match to a single extended property and a value restriction.",
"innerError": {
"request-id": "aca7c8ed-6e30-4490-8feb-7f1d2aed6b88",
"date": "2017-04-04T20:38:28"
}
}
}
does it mean that I also have to filter by value and not only id?
That would be an issue because I want the events that have the property set, but I don't know the value beforehand, I want to read it after I get a push notification.
Is there a way to get events which simply have a custom property set by my add-in, and subscribe to push notifications for events which has this custom property?
EDIT:
When I change id to PropertyId as suggested in the answer I'm getting:
{
"error": {
"code": "BadRequest",
"message": "Could not find a property named 'PropertyId' on type 'microsoft.graph.singleValueLegacyExtendedProperty'.",
"innerError": {
"request-id": "1d3db71e-6ee2-4680-9317-64687813c52a",
"date": "2017-04-05T13:49:45"
}
}
}
EDIT-2:
Now when I add filtering by value, it works:
/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af' and ep/value eq 'foo')
but I wan't all the events with that property regardless the value of it...
EDIT-3
No trying by filtering by value but using the non-equal ne operator:
/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af' and ep/value ne 'Foo')
it seems to work, but this time it looks like it just ignores the filter and returns all events, with and without that custom property set from the add-in.
After several tries I found a way to filter for events/messages that have a custom property regardless it's value:
https://graph.microsoft.com/v1.0/me/events/?$filter=singleValueExtendedProperties/any(ep: ep/id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-b7ff386a-234a-4a38-84bc-e5ae4684b7af' and ep/value ne null)
with the added important part being and ep/value ne null, whereas something like and ep/value ne 'fooo' didn't work, it just returned everything.
Above filtering works also for filtering of events for which we want subscribe to push events.
I believe the filter query should be
PropertyId eq ....
instead of Id eq ...