Reputation: 11
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. I have ended up doing the following 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
Upvotes: 0
Views: 684
Reputation: 2893
EWS doesn't support CORS. I am guessing that is why your request isn't succeeding. Can you please show us the error you are receiving. We are working on adding CORS support for Office 365 REST APIs for Mail, Calendar and Contacts and this should be available soon. Would that work for you?
Upvotes: 1