5

I am implementing an add-in for Outlook, the add-in gets an attachment and sends it to my server for processing. It works flawlessly on https://outlook.office.com but fails to run Outlook 2016 for Mac.

Here is the API I am trying to access:

var getMessageUrl =Office.context.mailbox.restUrl + '/v2.0/me/messages/' +
    {messageID} + "/attachments/" + {attachmentID};

var attachmentID = Office.context.mailbox.item.attachments[0].id;
var messageID = getItemRestId();

$.ajax({
    url: getMessageUrl,
    dataType: 'json',
    headers: {
        'Authorization': 'Bearer ' + outlookToken
    }
}).done(function 1(response) {
    //upload the blob to my server
}).fail(function (error) {
    //call authorise to get a new token
});

function getItemRestId() {
    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
        );
    }
}

Using Outlook 2016 for Mac, I get a 401 from the above API.

Also, the auth_token I get from calling getCallbackTokenAsync on Outlook 2016 for Mac is different than the one I get in a browser:

Office.context.mailbox.getCallbackTokenAsync({isRest: true}, function (result) {
    if (result.status === "succeeded") {
        //save result.value
    } 
    else {
        //error condition
    }
});

The values in my manifest are:

<Set Name="MailBox" MinVersion="1.3"/>
<Permissions>ReadWriteMailbox</Permissions>

Can someone point out what I am doing wrong here?

UPDATE As per Jason's suggestion, I checked the token I received on jwt.io The versions of the token are different on the browser and on the mac app.

On the Browser: "ver": "Exchange.Callback.V2" On the Mac App: "ver": "Exchange.Callback.V1" 

How do I get the outlook_mac_app to return v2 of the token?

EmptyCup
  • 421
  • 4
  • 14
  • 2
    You should include the complete error, which should be available in the body of the response. It would also be a good idea to parse the tokens using https://jwt.io to look for obvious differences. At first glance your code looks fine. – Jason Johnston Feb 01 '18 at 14:35
  • @jasonJohnston I have updated the question with the results from jwt.io. The token's are of different version hence the 401 error. – EmptyCup Feb 02 '18 at 06:26
  • You should be getting a V2 token if you have ReadWriteMailbox. If you're not, there may be a bug in Outlook Mac. I haven't seen this behavior here but I'm part of the Office Insiders Fast program, so I get the latest updates. Can you check for updates on your client and confirm what version you're using? – Jason Johnston Feb 02 '18 at 13:57
  • I'm running version 16.9 build 180116 – EmptyCup Feb 04 '18 at 05:22
  • That's likely the issue. I have 16.10 180114 and I get a proper token. It sounds like you have the latest release build, not part of Office Insider. Can you try the Office Insider build (it's an option in the updater) just to rule out any other issues? – Jason Johnston Feb 05 '18 at 15:16
  • Yep! Just updated and everything works fine. – EmptyCup Feb 12 '18 at 06:38

1 Answers1

1

I cannot comment, so posting this as an answer.

I was hitting 403 for attachments in Outlook for Mac 2016, not sure if they are related, but you could take a look at it here https://github.com/OfficeDev/outlook-add-in-command-demo/issues/30

Abhishek S Jain
  • 144
  • 1
  • 10
  • I tried running their RestCaller code inside my addin, Same issue there. I get {"readyState":0,"status":0,"statusText":"error"}. The token versions are different. – EmptyCup Feb 02 '18 at 06:44