I'm developing an Outlook add-in, in which I grab the mailbox item id and send it to an API. The API uses the Microsoft Graph SDK to fetch the message item by the given id. This scenario worked fine so far, but now I'm struggling with a strange format mismatch between the id I get from Office.js and the id from Graph.
Office.context.mailbox.item.itemId returns ...MlPrBwD/Cohwu0F...
Graph returns ...MlPrBwD-Cohwu0F
So Office.js returns the id containing /C where Graph returns -C in it.
Any ideas?
I'm not sure but I think that the id returned by Office.context.mailbox.item.itemId is an EWS item id.
You can convert it to rest/graph item id by using Office.context.mailbox.convertToRestId.
Related
In Microsoft Graph API, how do you retrieve a specific mail using the Id (Mail ID)?
This is what I tried :
$filter => "Id eq 'AQMkADYwZWEyZDQy...someRandomID'"
but the response I get is the property id does not support filtering
Yes. The property 'Id' does not support filtering for List messages.
You should retrieve a specific mail using the Id (Mail ID) through Get message.
GET https://graph.microsoft.com/v1.0/me/messages/{Mail ID}
Previously I used Microsoft EWS API to retrieve emails. It has a field called "References", now I am upgrading to MS Graph and couldn't find this particular field via REST API. Note that I could find and retrieve all other fields except this.
The References property is just the References Message header so you get that header as part of the IntenetMessageHeaders https://learn.microsoft.com/en-us/graph/api/message-get?view=graph-rest-1.0
GET https://graph.microsoft.com/v1.0/me/messages/AAMkADhAAAW-VPeAAA=/?$select=internetMessageHeaders
You can also request the underlying Extended Mapi property PR_INTERNET_REFERENCES also eg
https://graph.microsoft.com/v1.0/me/messages?$expand=singleValueExtendedProperties($filter=id eq 'String 0x1039')
Using Microsoft Graph, how can I determine which message an outgoing message is a reply to?
The internetMessageHeaders property is not available for items in the Sent Items folder of mailboxes (using the Graph API, at least -- they are available using EWS or IMAP). If it were, I'd look for the in-reply-to header. In the absence of this, is there something in the standard Graph message properties that will tell me this?
You can check the "Subject" or "bodyPreview" to check if the content contains "RE:", if the answer is yes, the message is reply to.
You can group the message by conversationId and then order by lastModifiedDateTime. This way can check if the message is the original one, if it is not ,it will be reply-to/follow-up one.
Get the message list first(/me/messages or /users/{id | userPrincipalName}/messages and so on), and then foreach the message id to call reply api(/users/{id | userPrincipalName}/messages/{id}/reply and so on). The result in the reply is a reply to.
To Test this, you can use the Graph Explorer first and then paste the JSON to a JSON viewer tool. For further use, you need to use net/java and so on to handle.
API reference: https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/resources/message
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/message_reply
My intention is to build a Machine Learning program that will give a recommendation for archiving email item by reading all previous email history.
For that, I am trying to read all the email item from:
https://graph.microsoft.com/beta/me/messages
First I am getting the total number of email items in my account using /messages?$count=true which returns 1881 as the result.
Then I am trying to get all the 1881 item using:
https://graph.microsoft.com/beta/me/messages?$top=1881
But the problem is that returns 976 email items. Where are the rest of the email item? How I can find them?
Are you getting a #odata:nextLink property in your response?
If that's the case, you might need to send another request with a skiptoken parameter. It should contain a value from the #odata:nextLink response property.
On the "paging" documentation page - https://developer.microsoft.com/en-us/graph/docs/concepts/paging - it is specified that different APIs have different max page size. It's possible that the endpoint for fetching emails does not support a page size of 1881. In that case, you might need to access a second page of the results.
Another suggestion is to replace beta endpoint with the V1 API call because me/messages is available there also - https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/user_list_messages
We have integrated outlook to our iOS application using Microsoft Graph API. We have a use case where we have to filter outlook messages by attachment name or by subject. We are using query parameters to hit graph API.
Link to microsoft documentation.
As per above documentation, $search parameter is used to filter outlook messages. When are hitting below API, we are getting wrong responses. It’s returning messages which have “Test Mail” in both subject and message body. But it should return only the messages whose subject line is “Test Mail”.
https://graph.microsoft.com/v1.0/me/messages?$search="subject:Test Mail”
The same problem we are facing when we filter messages by attachment name, by hitting below API. In fact we are getting a empty response in this case.
https://graph.microsoft.com/v1.0/me/messages?$search=“attachments:test.png”
Is the above URL formation is correct? Why we’re not getting desired response? Please help us out on this.
For searching Subject only, you can use:
/v1.0/me/messages?$search="subject:search term"
or a filter:
/v1.0/me/messages?$filter=contains(subject, 'my search term')
(in this method the search term must exactly match a portion of the subject string)
For searching attachments only, you must use the keyword 'attachment' instead of 'attachments' (exchange documentation):
/v1.0/me/messages?$search="attachment:search term"