OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
682 stars 95 forks source link

makeEwsRequestAsync throws an error for delegate calendar #734

Closed chopraniitn closed 5 years ago

chopraniitn commented 5 years ago

I am working on office 365 addin at the moment and just trying to use office js function for delegate calendars. some of the functions works ok , but when i try to use makeEwsRequestAsync method, it get fails and give ErrorAcessDenied as Error code and message i get as Office extension have no permissions to access any other mailboxes then the mailbox provided in the user context

i have tried beta version of office js as well, but no luck.

This is how i am using the function

`var callGetItem = function(id) { mailbox.makeEwsRequestAsync(getItemRequest(id), function(asyncResult) { var parser = new X2JS(); var json = parser.xml_str2json(asyncResult.value); getItemJson = json.Envelope.Body.GetItemResponse.ResponseMessages; logMessage("getItem request - call number " + asyncCount); // if (getItemJson.GetItemResponseMessage._ResponseClass !== "Error") { logMessage("getItem request success"); changeKey = getItemJson.GetItemResponseMessage.Items.CalendarItem.ItemId._ChangeKey; logMessage("getItem request ChangeKey: " + changeKey, true); checkRecurrencePattern(getItemJson.GetItemResponseMessage.Items.CalendarItem); if (customPropsString === void(0) || customPropsString == "") { if (getItemJson.GetItemResponseMessage.Items.CalendarItem.ExtendedProperty) { logMessage("Custom properties value: " + getItemJson.GetItemResponseMessage.Items.CalendarItem.ExtendedProperty.Value.toString()); saveCustomPropertyJavaScript(getItemJson.GetItemResponseMessage.Items.CalendarItem.ExtendedProperty.Value.toString()); }

        }
    } else {
        logMessage("getItem request error");
        asyncCount++;
        setTimeout(function() {
            callGetItem(id);
        }, 5000);
    }
});

}; `

var getItemRequest = function(id) { var request = '<?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>' + ' <RequestServerVersion Version="Exchange2016" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' + ' </soap:Header>' + ' <soap:Body>' + ' <GetItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">' + ' <ItemShape>' + ' <t:BaseShape>IdOnly</t:BaseShape>' + ' <t:AdditionalProperties>' + ' <t:FieldURI FieldURI="item:Subject"/>' + ' <t:FieldURI FieldURI="item:Body"/>' + ' <t:FieldURI FieldURI="calendar:Organizer"/>' + ' <t:FieldURI FieldURI="calendar:Resources"/>' + ' <t:FieldURI FieldURI="calendar:IsRecurring"/>' + ' <t:FieldURI FieldURI="calendar:Recurrence"/>' + ' <t:FieldURI FieldURI="calendar:FirstOccurrence"/>' + ' <t:FieldURI FieldURI="calendar:LastOccurrence"/>' + ' <t:ExtendedFieldURI DistinguishedPropertySetId="PublicStrings" PropertyName="DDL Reference" PropertyType="String" />' + ' </t:AdditionalProperties>' + ' </ItemShape>' + ' <ItemIds><t:ItemId Id="' + id + '"/></ItemIds>' + ' </GetItem>' + ' </soap:Body>' + '</soap:Envelope>'; return request; };

i am using insider version of outlook with build 16.0.12112.20000 32 bit version.

Does any one know about this issue or any workaround or let me know if i am missing something?

JuaneloJuanelo commented 5 years ago

@chopraniitn : thanks so much for trying our Preview APIs ! we are investingating this issue, meanwhile i have a couple of questions for you:

  1. Is there a reason why you are not using the Microsoft Graph as opposed to EWS? Turns that the token we generate to make the EWS request does not support delegate scenarios. With REST/Graph you could so we will follow up with some documentation on it.
  2. We seem to support all the properties you are asking for on your SOAP request, can you ellaborate why the need to make the EWS call?

THanks!

JuaneloJuanelo commented 5 years ago

btw this exact issue was duplicated in stack: https://stackoverflow.com/questions/58014027/makeewsrequestasync-throws-an-error-for-delegate-calendar

chopraniitn commented 5 years ago

HI Juan,

we are exploring Graph API at the moment and because they are at quite young stage so we are bit cautious in implementing those. Eventually we will. But at the moment I am trying to resolve an ongoing issue which is using makeEwsRequestAsync on a delegate calendar. it works fine on a user calendar.

Thanks Nitin

On Fri, Sep 20, 2019 at 1:46 AM Juan Balmori notifications@github.com wrote:

@chopraniitn https://github.com/chopraniitn : thanks so much for trying our Preview APIs ! we are investingating this issue, meanwhile i have a couple of questions for you:

  1. Is there a reason why you are not using the Microsoft Graph as opposed to EWS?
  2. We seem to support all the properties you are asking for on your SOAP request, can you ellaborate why the need to make the EWS call?

THanks!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/OfficeDev/office-js/issues/734?email_source=notifications&email_token=ANH2BQ6AL23FYAYFADAIM5LQKQMPZA5CNFSM4IYM2EFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD7FG2WY#issuecomment-533359963, or mute the thread https://github.com/notifications/unsubscribe-auth/ANH2BQ7OBVE342UGCVDTWGTQKQMPZANCNFSM4IYM2EFA .

--

Nitin Chopra

Systems Developer, Manhattan Space Scheduling

Trimble / Real Estate & Workplace Solutions

Office: +44 (0)20 30969530

Nitn_Chopra@trimble.com

http://realestate.trimble.com

[image: cid:image002.jpg@01CFBC8C.548947C0] https://twitter.com/ManhattanSW [image: cid:image003.jpg@01CFBC8C.548947C0] http://www.linkedin.com/company/manhattan-software

The information contained in this message is intended for the addressee only and may contain confidential and/or privileged information. If you are not the addressee, please delete this message and notify the sender and do not copy or distribute this message or disclose its contents to anyone. Any views or opinions expressed in this message are those of the author and do not necessarily represent those of Trimble UK Ltd. No reliance may be placed on this message without written confirmation of its contents from an authorised representative.

Trimble UK Ltd is a company registered in England. No: 04069823. Registered address: 1 Bath Street, Ipswich IP2 8SD.

chopraniitn commented 5 years ago

btw this exact issue was duplicated in stack: https://stackoverflow.com/questions/58014027/makeewsrequestasync-throws-an-error-for-delegate-calendar

yes, that was me. but i did not get response in past so was not too hopeful if i get any response there. but i had some hope here on git and see i was not wrong :)

JuaneloJuanelo commented 5 years ago

HI Juan,

we are exploring Graph API at the moment and because they are at quite young stage so we are bit cautious in implementing those. Eventually we will. But at the moment I am trying to resolve an ongoing issue which is using makeEwsRequestAsync on a delegate calendar. it works fine on a user calendar.

Thanks Nitin …

The Graph is the way to go on this scenario, as mentioned earlier, the token you get with EWS does now work with delegates...

chopraniitn commented 5 years ago

HI Juan, we are exploring Graph API at the moment and because they are at quite young stage so we are bit cautious in implementing those. Eventually we will. But at the moment I am trying to resolve an ongoing issue which is using makeEwsRequestAsync on a delegate calendar. it works fine on a user calendar. Thanks Nitin …

The Graph is the way to go on this scenario, as mentioned earlier, the token you get with EWS does now work with delegates...

So, the conclusion is makeEwsRequestAsync wont work on delegate calendars in any circumstances and graph is the only way.

And for graph to work on delegate calendars with office js, do i need to use getSharedPropertiesAsync (in preview) first? or i can use it straight away.

JuaneloJuanelo commented 5 years ago

HI Juan, we are exploring Graph API at the moment and because they are at quite young stage so we are bit cautious in implementing those. Eventually we will. But at the moment I am trying to resolve an ongoing issue which is using makeEwsRequestAsync on a delegate calendar. it works fine on a user calendar. Thanks Nitin …

The Graph is the way to go on this scenario, as mentioned earlier, the token you get with EWS does now work with delegates...

You can either use Outlook REST API or Graph for it. Here is a help topic you can use to get an idea on how to make the call. Warning the: targetRestUrl property does not work in Windows, there its named restUrl, please note that API is in preview, we are renaming it so its consistent across all platforms. (the final name will be targetRestUrl)

chopraniitn commented 5 years ago

Based on discussion it seems like graph api is only way to handle delegate scenario. so closing it. Thanks @JuaneloJuanelo

sarea commented 5 years ago

I got similar issue, tried to set the internet message header for a delegated account using makeEwsRequestAsync and got access denied, I found this SO very helpful knowing that this is not very clear in the documentation. there's another way to change the header internetHeaders.setAsync (still in preview)