Please find below a code sample accessing all the message of an outlook conversation using the REST API. The use of office promises is compatible with IE11 and makes the code more readable than cascading async calls.
The getCallbackTokenAsync call is required. It gets an OAuth token which is then used to authenticate the REST API xhr request against Exchange. Feel free to change the called URL to match your use case.
//https://stackoverflow.com/questions/44377278/get-first-email-from-conversation-id-using-microsoft-graph
//https://graph.microsoft.com/v1.0/me/messages?$filter=(conversationId eq 'yourConversationId')
function getEmailConversationMessagesPromise(conversationId) {
return new Office.Promise(function(resolve, reject) {
Office.context.mailbox.getCallbackTokenAsync({ isRest: true }, function (getCallbackTokenAsyncResult) {
var token = getCallbackTokenAsyncResult.value;
var searchMessagesUrl = Office.context.mailbox.restUrl + "/v2.0/me/messages/?$filter=conversationId eq '" + encodeURIComponent(conversationId) +"'";
var xhr = new XMLHttpRequest();
xhr.open('GET', searchMessagesUrl);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.onload = function (e) {
messages = JSON.parse(this.response).value;
resolve(messages);
}
xhr.onerror = function () {
reject("Error when trying to retrieve email conversation messages list");
}
xhr.send();
});
});
}