yanik
yanik

Reputation: 818

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

I followed this document https://learn.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!

Upvotes: 2

Views: 1933

Answers (2)

panwar
panwar

Reputation: 1121

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.

Upvotes: 2

Marc LaFleur
Marc LaFleur

Reputation: 33124

Since you're not getting a value from the restUrl property, I suspect you're using an on-prem Exchange Server. This is a known issue with on-prem installations. This is also why using the https://outlook.office.com won't work (you're server isn't located at that URI).

You might be able to get around this using the Hybrid Deployment configuration. This allows you to execute Microsoft Graph API calls against a local server. That said, I have not tried this so it may not work in this scenario. Given that all of these components (1.5 and Hybrid) are in Preview, unexpected results should always be expected.

Upvotes: 1

Related Questions