Call EWS from SharePoint 2013 SharePoint Hosted App (JavaScript) in Office 365

I am trying to call the exchange web service (EWS) of an exchange online server from a SharePoint hosted app. I am limited thus to the use of Javascript. During my call i am always getting an access denied error.

The body of the SOAP request is good since I have tested it using a client application, but I am not being able to get it to work via a jquery ajax call. I am sure that this is an authentification issue and I have no problem sending the credentials during the call. I have added them in the header. This is what I have ended up doing but still no luck.

functionGetUnReadEmailCount() {

varsoapPacket = "<?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:Header>'+
'<wsse:Security>'+
'<wsse:UsernameToken>'+
'<wsse:Username>******</wsse:Username>'+
'<wsse:Password>******</wsse:Password>'+
'</wsse:UsernameToken>'+
'</wsse:Security>'+
'</soap:Header>'+
"<soap:Body>"+
"<FindItem xmlns='http://schemas.microsoft.com/exchange/services/2006/messages' xmlns:t='http://schemas.microsoft.com/exchange/services/2006/types'Traversal='Shallow'>"+
"<ItemShape>"+
"<t:BaseShape>IdOnly</t:BaseShape>"+
"</ItemShape>"+
"<IndexedPageItemView MaxEntriesReturned='50' Offset='0' BasePoint='Beginning' />"+
"<Restriction>"+
"<t:IsEqualTo>"+
"<t:FieldURI FieldURI='message:IsRead' />"+
"<t:FieldURIOrConstant>"+
"<t:Constant Value='false' />"+
"</t:FieldURIOrConstant>"+
"</t:IsEqualTo>"+
"</Restriction>"+
"<ParentFolderIds>"+
"<t:DistinguishedFolderId Id='inbox' />"+
"</ParentFolderIds>"+
"</FindItem>"+
"</soap:Body>"+
"</soap:Envelope>";

$.support.cors = true;
$.ajax({
        url: "https://outlook.office365.com/EWS/Exchange.asmx",
        type: "POST",
        dataType: "xml",
        data: soapPacket,
        complete: processResult,
        error: OnError,
        contentType: "text/xml; charset=\"utf-8\""
});
}

Any help is highly appreciated.

Thanks.

Elie

April 16th, 2015 1:29pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics