Outllok add in REST call: RequestBroker-ParseUri -- "Resource not found for the segment 'messages'."

Viewed 1240

I followed this document https://docs.microsoft.com/en-us/outlook/add-ins/use-rest-api, and receive an error on rest api call:

{"error":{"code":"RequestBroker-ParseUri","message":"Resource not found for the segment 'messages'."}}

Token and message ID have correct values, code is from docs, the only thing I did replace is Office.context.mailbox.restUrl for default https://outlook.office.com since first one is empty for me (why?)

Actually code:

function getItemRestId() {
    // Currently the only Outlook Mobile version that supports add-ins
    // is Outlook for iOS.
    if (Office.context.mailbox.diagnostics.hostName === 'OutlookIOS') {
        // itemId is already REST-formatted
        return Office.context.mailbox.item.itemId;
    } else {
      // Convert to an item ID for API v2.0
        return Office.context.mailbox.convertToRestId(
            Office.context.mailbox.item.itemId,
            Office.MailboxEnums.RestVersion.v2_0
      );
    }
}

function getCurrentItem(accessToken) {
    var itemId = getItemRestId();
    var getMessageUrl = 'https://outlook.office.com' +
      '/api/v2.0/messages/' + itemId;

  $.ajax({
      url: getMessageUrl,
      dataType: 'json',
      headers: { 'Authorization': 'Bearer ' + accessToken }
  }).done(function(item){
      var subject = item.Subject;
  }).fail(function(error){
      // log error is here 
  });
}

Office.context.mailbox.getCallbackTokenAsync({isRest: true}, function(result){
    if (result.status === "succeeded") {
        var accessToken = result.value;
        // Use the access token
      getCurrentItem(accessToken);
      } else {
        // Handle the error
      }
});

What I did wrong? Do you think it's because I replaced restUrl value? I do use custom domain email.

Thank you for your time!

2 Answers

I was facing the same issue.

i used

var getMessageUrl = 'https://outlook.office.com/api/v2.0/me/messages/'+ itemId+"/attachments";

instead of below url:

var getMessageUrl = 'https://outlook.office.com/api/v2.0/messages/' + itemId;

API gives proper response after using the first API.

Related