Microsoft Graph API - Filter messages response contains invalid JSON - microsoft-graph-api

I am making a request to the Microsoft Graph API to retrieve all emails that have been modified since a particular date. The request is the below:
https://graph.microsoft.com/v1.0/users/59687355-748d-4d9c-aa4c-d0c1d2086eff/messages/?$select=bccRecipients,categories,ccRecipients,changeKey,conversationId,conversationIndex,createdDateTime,flag,from,hasAttachments,id,importance,inferenceClassification,internetMessageId,isDeliveryReceiptRequested,isRead,isReadReceiptRequested,lastModifiedDateTime,parentFolderId,receivedDateTime,replyTo,sender,sentDateTime,subject,toRecipients,webLink&$filter=lastModifiedDateTime gt 2022-10-07T10:49:27Z and lastModifiedDateTime lt 2022-10-14T10:49:27Z and isDraft eq false and parentFolderId ne 'conversationhistory' and parentFolderId ne 'junkemail' and parentFolderId ne 'outbox' and parentFolderId ne 'recoverableitemsdeletions' and parentFolderId ne 'scheduled' and parentFolderId ne 'searchfolders'&$orderby=lastModifiedDateTime asc&$top=100
Most of the time it is successful. But sometimes the response is malformed:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('59687355-748d-4d9c-aa4c-d0c1d2086eff')/messages(bccRecipients,categories,ccRecipients,changeKey,conversationId,conversationIndex,createdDateTime,flag,from,hasAttachments,id,importance,inferenceClassification,internetMessageId,isDeliveryReceiptRequested,isRead,isReadReceiptRequested,lastModifiedDateTime,parentFolderId,receivedDateTime,replyTo,sender,sentDateTime,subject,toRecipients,webLink)",
"value": [
{
"#odata.etag": "W/\"CQAAABYAAABsk7XI0Ba5RLTZiPmnkZbZAAFYXkB3\"",
"id": "AAMkADg5NjZhMjkzLWIyODQtNDFkNy1hOWMzLTBhODVlZGFjMGIyMQBGAAAAAADk-kLFG1rtR5MSTyO-jKygBwBsk7XI0Ba5RLTZiPmnkZbZAAAAAAEJAABsk7XI0Ba5RLTZiPmnkZbZAAFZu3S4AAA=",
...
},
{
"#odata.etag": "W/\"CQAAABYAAABsk7XI0Ba5RLTZiPmnkZbZAAFYXkCB\"",
"id": "AAMkADg5NjZhMjkzLWIyODQtNDFkNy1hOWMzLTBhODVlZGFjMGIyMQBGAAAAAADk-kLFG1rtR5MSTyO-jKygBwBsk7XI0Ba5RLTZiPmnkZbZAAAAAAEKAABsk7XI0Ba5RLTZiPmnkZbZAAFZuvoVAAA=",
...
},
{
"#odata.etag": "W/\"CQAAABYAAABsk7XI0Ba5RLTZiPmnkZbZAAFYXkCJ\"",
"id": "AAMkADg5NjZhMjkzLWIyODQtNDFkNy1hOWMzLTBhODVlZGFjMGIyMQBGAAAAAADk-kLFG1rtR5MSTyO-jKygBwBsk7XI0Ba5RLTZiPmnkZbZAAAAAAEKAABsk7XI0Ba5RLTZiPmnkZbZAAFZuvoWAAA=",
...
} {
"error": {
"code": "ErrorItemNotFound",
"message": "The specified object was not found in the store., The process failed to get the correct properties."
}
}
Retrying the request usually works. But the mix of a successful list response with the ErrorItemNotFound error seems like a Microsoft Graph API bug.
A possible explanation for the bug: The Graph API has retrieved a list of IDs matching the query. It then retrieves each record to assemble the response. Due to mutable IDs the email cannot be found. The error is appended to the response and the response is returned. Maybe the error should have been returned on its own to indicate that the request should be retried. Or maybe this error should be ignored and the rest of the list can be generated and returned.

Related

Filter event objects by body content

I'm trying to query calendar events using the Graph API and I would like to filter them by category and body content.
The goal is to get any event object that is in category "Test" and contains the string "FooBar" in its body content.
I tried to query the Graph API with the following request:
https://graph.microsoft.com/v1.0/me/events?$filter=(categories/any(x:x eq 'Test') and contains(body/content, 'FooBar'))
The response is a 500 error message:
{
"error": {
"code": "ErrorInternalServerError",
"message": "An internal server error occurred. The operation failed.",
//...
}
}
The "categories" filter clause works fine on its own but as soon as I put the "body/content" clause back in I get the aforementioned error response.
The json object I get from the Graph API looks like this (stripped down for better readability)
{
"value": [
{
"categories": [
"Test"
],
"bodyPreview": "FooBar",
"body": {
"contentType": "html",
"content": "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"></head><body><div class=\"BodyFragment\"></div><div class=\"BodyFragment\"><font size=\"2\"><span style=\"font-size:11pt\"><div class=\"PlainText\">FooBar</div></span></font></div></body></html>"
}
}
]
}
Is there something wrong with my filter clause or might this be an issue with Graph API itself?
I first tried to filter by bodyPreview but the error response I got clearly said that this field cannot be filtered by so I guess body/content should be possible.
The filtering by body/content is not supported for events.
I've tried similar query for messages and it works fine, so your filter clause is correct.
GET https://graph.microsoft.com/v1.0/me/messages?$filter=(categories/any(x:x eq 'Test') and contains(body/content, 'FooBar'))

Receiving 400s and 500s when attempting to get singleValueExtendedProperties

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.

Unsupported Media Type - 415 error in POST request in Graph Explorer

I am trying out Graph Explorer. I am able to get my profile from https://graph.microsoft.com/v1.0/me/.
But when I try to create a device using the Graph Explorer, it is returning Unsupported Media Type - 415 response.
My request and response are:
Request
POST https://graph.microsoft.com/v1.0/devices
Request headers
Content-type: application/json
Request body
{
"accountEnabled": false,
"alternativeSecurityIds": [
{
"type": 3,
"key": "base64Y3YxN2E1MWFlYw=="
}
],
"deviceId": "4c299165-6e8f-4b45-a5ba-c5d250a707ff",
"displayName": "Test device",
"operatingSystem": "linux",
"operatingSystemVersion": "1"
}
I have given the consent for all permissions under Modify permissions section.
Response
Unsupported Media Type - 415 - 1168ms
{
"error": {
"code": "Request_BadRequest",
"message": "The specified content type 'application/json;odata=minimalmetadata, application/json' contains either no media type or more than one media type, which is not allowed. You must specify exactly one media type as the content type.",
"innerError": {
"request-id": "11235ffc-1fb3-4324-a832-2c92274e98bf",
"date": "2020-04-06T16:55:17"
}
}
}
Edit
value of deviceId in the request data
"DeviceId" AND "Key" that you are passing in Request body should be Unique identifier. Change you sample Device-Id & Key and try again. It worked for me. and you also increased the length of device id by appending 1 at end.
Documentation for accountEnabled here.

Cannot get a person by its id using ms-graph people API

I'm using the Microsoft Graph People API and when I look at the docs here you can get a person by using its id:
I use the Graph Explorer to get people with the following API call:
https://graph.microsoft.com/v1.0/me/people?$select=id
I successfully get a list of ids.
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users...",
"#odata.nextLink": "https://graph.microsoft.com/v1.0/me/people?$select=id&$skip=10",
"value": [
{
"id": "ddb9e9e4-a4cc-46ee-93f4-ba135920c84a"
},
{
"id": "37136f8b-33b3-4596-a63b-d41dc8edda34"
},
{
"id": "8c13d891-bd2f-42e5-8650-450b3318f8e3"
}
]
}
Then I use one of the ids to get more info about a single person by using this call:
https://graph.microsoft.com/v1.0/me/people/ddb9e9e4-a4cc-46ee-93f4-ba135920c84a
And I get an error:
{
"error": {
"code": "ErrorInternalServerError",
"message": "An internal server error occurred. The operation failed.",
"innerError": {
"request-id": "6e138441-5e1d-4f04-a87b-8141547cbb07",
"date": "2018-05-04T06:36:22"
}
}
}
Am I doing sth wrong ?
I'm also getting this error when following Microsoft's documenation.
As a workaround I added a filter.
https://graph.microsoft.com/v1.0/me/people?$filter=id eq 'ddb9e9e4-a4cc-46ee-93f4-ba135920c84a'
Unfortunately is seems that filtering by id is not supported at this time.
If you have the persons name you can use a filter like this:
https://graph.microsoft.com/v1.0/me/people?$filter=givenName eq 'Baris'
At the end of the day I prefer to use /users endpoint to get this type of information.
https://graph.microsoft.com/v1.0/users?$filter=id eq 'ddb9e9e4-a4cc-46ee-93f4-ba135920c84a'
or
https://graph.microsoft.com/v1.0/users?$filter=startswith(givenName, 'Baris')
Hope this helps!

MS GraphAPI returns an InternalServerError for /messages requests with specific filter expressions

We have encountered the following InternalServerError from the MS GraphAPI when invoking the /messages endpoint for several users and filter expressions.
For example, the following request consistently fails:
The request:
GET https://graph.microsoft.com/v1.0/users/{userPrincipalName}/messages?$top=100&$filter=isDraft eq false and createdDateTime ge 2017-06-09T05:11:58Z&$select=id,internetMessageId,from,sender,replyTo,subject,body,toRecipients,ccRecipients,bccRecipients,receivedDateTime,sentDateTime,createdDateTime,hasAttachments,parentFolderId,isDraft,isRead,changeKey,conversationId,parentFolderId
The response:
{
"error": {
"code": "InternalServerError",
"message": "Error while processing response.",
"innerError": {
"request-id": "b1ccb699-17da-4faf-9b8e-eba629be21e9",
"date": "2017-07-28T21:33:09"
}
}
}
It is important to note that if the timestamp in the filter expression is modified (e.g. by using a later timestamp) then the requests succeeds.
Changing the $top parameter from 100 to 10 also produces a valid 200 response.
Unfortunately, I cannot share the userPrincipalName in this post.
Is there a known issue with certain messages that may result in an internal error when retrieving messages? The request-id is in the response, so hopefully that could provide some clues.
Any help would be much appreciated!
I got the same problem in this error.
Try to downsize the header Prefer:odata.maxpagesize=200
or downsize the top query
It works for me.

Resources