2
votes

We develop an Outlook Add-In using the office JavaScript api and need to Update a category for a mail message.

When trying to call UpdateItem with Exchange EWS, using the add-in token - it fails with 500.

See request and response at: http://pastebin.com/55x2d2Ht

  1. The app's manifest permissions is ReadWriteMailbox (highest)
  2. When the app is selected in OWA /manageapps - it displays "When this adding is clicked, it will be able to: Read, create and update email in your mailbox"
  3. Tried both token from mailbox.getCallbackTokenAsync and using makeEwsRequestAsync.
  4. EWS GetItem and CreateItem operations succeeds - it is only UpdateItem that is failing
  5. Response to UpdateItem: 500 The requested web method is unavailable to this caller or application.
  6. The fact that it is 500 (and not 403) may imply that the UpdateItem operation is blocked for addin app altogether
  7. The jwt token (from getCallbackTokenAsync) doesn't have 'scp' key
  8. If the same UpdateItem XML Soap packet is sent with another token, from a test OAuth app registered in Azure with permissions Read/Write to Exchange --> it succeeds. This app jwt token with "scp": "full_access_as_user Mail.Read Mail.ReadWrite Mail.Send"
  9. Tried with another exchange user with the add-in token - also fails.
  10. Office AddIn docs states that EWS UpdateItem operation is supported in the context of addin. See Office Dev Center
  11. Summary: Only Ews UpdateItem with the Addin OAuth token fails. Other operations succeeds and Posting UpdateItem using other tokens (or Basic Auth) also succeeds.
1

1 Answers

2
votes

You should be able to use UpdateItem with makeEwsRequestAsync. You cannot use getCallbackTokenAsync because this call returns a token that is read only that can only be used for GetItem and GetAttachment. When making a request with makeEwsRequestAsync, your XML SOAP request (the data parameter in makeEwsRequest should look like this:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
               xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
  <soap:Body>
    <UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AutoResolve" xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
      <ItemChanges>
        <t:ItemChange>
          <t:ItemId Id = "AAMkAGI3NDEzZjRhLWU3ZjktNGViNy04MTI1LWFhOWRiZDRlY2QwNABGAAAAAADBaXFYA4KPQqsQBpmZF2+2BwAa6KJzOcvaRKcc5UfLbF5tAAAA4fK1AAACk4HLLuxASqDPNieBkIv8AANIKlICAAA=" ChangeKey="CQAAABYAAAACk4HLLuxASqDPNieBkIv8AANIb3mG"/>
          <t:Updates>
            <t:SetItemField>
              <t:FieldURI FieldURI = "item:Categories" />
              <t:Message>
                <t:Categories>
                  <t:String>Workout</t:String>
                </t:Categories>
              </t:Message>
            </t:SetItemField>
          </t:Updates>
        </t:ItemChange>
      </ItemChanges>
    </UpdateItem>
  </soap:Body>
</soap:Envelope>

You should not need to pass in a callback token in order call makeEwsRequestAsync.