Creating an Outlook Appointment with the JavaScript API for Office Apps


A very likely feature request of any Outlook app would be automatic creation of calendar items, e.g. appointments.

Unfortunately the MSDN documentation does not exactly specify how you do that, but it is simple when you know how, let me show you.

The JavaScript API unfortunately offers no direct way to create appointment or other Outlook/Exchange artifacts (meeting requests, todos, etc). What it does offer is a way to call Exchange Web Services (EWS) (msdn docs), and with EWS it is possible to do anything you can from Outlook. For a list of all the operations possible with EWS consult EWS operations in Exchange 2013

The hook into calling EWS provided by the Office API is:
Office.context.mailbox.makeEwsRequestAsync(<requestSoapString>, <callbackFunction>);
The is a string containing a full SOAP request, as the one you would construct if you were calling the webservice. The callback function is called when a response returns, with an argument where the response SOAP message is found in the value property.
function callback(asyncResult) {
var result = asyncResult.value;
var context = asyncResult.context;
All pretty straight forward. Building the SOAP message, might not be so straight forward, mostly because MSDN have a few different examples of CreateItem SOAP messages, and not all of them work apparently.
Here is the function I used for creating a test meeting request:
function createAppointment()
var result = ‘<?xml version="1.0" encoding="utf-8"?>’ +
‘<soap:Envelope xmlns:xsi=""’ +
‘ xmlns:xsd=""’ +
‘ xmlns:soap=""’ +
‘ xmlns:t="">’ +
‘ <soap:Header>’ +
‘ <RequestServerVersion Version="Exchange2013" xmlns="" soap:mustUnderstand="0" />’ +
‘ </soap:Header>’ +
‘<soap:Body>’ +
‘<CreateItem xmlns=""’ +
‘ xmlns:t=""’ +
‘ SendMeetingInvitations="SendToAllAndSaveCopy" >’ +
‘<t:DistinguishedFolderId Id="calendar"/>’+
‘<t:CalendarItem xmlns="">’+
‘<Subject>Planning Meeting</Subject>’+
‘<Body BodyType="Text">Business meeting about new customers.</Body>’+
‘<End>2014-04-02T15:00:00</End>’ +
‘<Location>Meeting Room A</Location>’+
‘<EmailAddress>[email protected]</EmailAddress>’+
return result;
Worth noticing is, the SOAP header, ensure that you have correct spacing and do include the first line defining the xml. It is very error prone to build a SOAP message as a JavaScript string, so you might not get it right at first, if it contains an error then the makeEwsRequestAsync will return an error 400.

Now you have SOAP message in place and you know how to call EWS from JavaScript, the last thing you need to do change the permission level for your Mail App for Outlook, “Read write mailbox” in the App Manifest. This is required in order to be able to call EWS.