0

I see this Access to Outlook RestAPI from an Outlook web Add-in question but nothing about attachment there.

I success to make outlook rest API request from my add-in follow https://dev.office.com/docs/add-ins/outlook/use-rest-api?product=outlook this tutorial . For example I success to get some message details), but I have 2 problems:

  1. I can't add attachment with outlook rest API call to message. I try to make call with the itemId like here:

    https://outlook.office.com/api/v2.0/me/messages/" + itemId +"/attachments
    

The error I get is:

{"error":{"code":"ErrorAccessDenied","message":"The api you are trying to access does not support item scoped OAuth."}}

I try to change permissions(ReadWriteMailbox/ReadWriteItem) on manifest but nothing help..

  1. Sometimes the call of Office.context.mailbox.getCallbackTokenAsync({ isRest: true }, function().... function work and return access token and sometimes return error , I don't know also what the reason. The error I get sometimes is:

    OSF.DDA.AsyncResult
    error:OSF.DDA.Error
    status:"failed"
    

Hope you could help me , thanks all!!

Community
  • 1
  • 1
OriEng
  • 1,424
  • 18
  • 34

1 Answers1

1

On #1, the error indicates that the token you have is scoped to just the current item. The REST API cannot use this kind of token for modifying attachments, so you get that error. The correct way that this should work is that you specify ReadWriteMailbox in your add-in manifest, and then the token you get back should be a mailbox-scoped token. However, there is currently a bug with desktop Outlook's handling of getCallbackTokenAsync that causes it to incorrectly still return an item-scoped token. That bug has been fixed but the update hasn't been publicly pushed yet.

If you want to check this, copy the token you get back and head over to https://jwt.io/. Paste it in the "Encoded" box and check the payload. If you see "ver": "Exchange.Callback.V1" it's the item-scoped token. If you see "ver": "Exchange.Callback.V2" it's the mailbox-scoped one.

On #2, I have no idea. It would be helpful if you could get a Fiddler trace on your Outlook client machine that catches the add-in making the token request.

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
  • First , thank you very much . I try to test again on Outlook 365 in browser and in Outlook desktop .I set permissions 'ReadWriteMailbox' in the manifest file and run. I get the access token and check it on jwt.io to find value of 'ver' and I get: "ver": "Exchange.Callback.V1" . So , you say that there is a bug?If I get Callback.V2 so I could add attachment to message ?And when it fixed? And , I found out why I get the error of access token (question 2 ) .The item must be saved before we get the access token so I save it with Office.context.mailbox.item.saveAsync function . Thanks again !! – OriEng Feb 26 '17 at 15:42
  • Yes, it's a bug in Outlook. This is fixed in builds after 16.0.7902.1000. I don't have a timeline for when this will be widely available. – Jason Johnston Feb 27 '17 at 13:34
  • I still have same error to add attachment using the outlook rest api ... there is a fix or something that release , when I check the JWE I have "ver": "Exchange.Callback.V1", ? tnx – OriEng Jul 05 '17 at 10:15
  • What is your Outlook version? – Jason Johnston Jul 05 '17 at 12:10
  • The outlook version I use or what ? I try in outlook OWA in chrome and in IE and also in Outlook desktop 2016 and I get same response .. – OriEng Jul 05 '17 at 12:26
  • Yes, the version you are using. – Jason Johnston Jul 05 '17 at 14:21
  • The version of outlook desktop is : 2016 MSO (16.0.8201.2102) 32 bit and in web I just use the main address : https://outlook.office.com/owa/ on IE and chrome . tnx for your help – OriEng Jul 05 '17 at 14:44
  • You should have the fixes for this. Are you familiar with using Fiddler? Our engineering team has asked if you can capture a Fiddler trace when Outlook desktop is making the request for the token. – Jason Johnston Jul 05 '17 at 20:42
  • I am running into the same issue, the token returned by getCallbackTokenAsync method returns an item scoped token. I need it to update certain extension property on a mail item. Is any workaround possible ? – Swasti Gupta Feb 28 '19 at 07:11