How to query EWS for a Calendar Message Body - outlook

I'm looking for a little more details than what was given in this answer: Exchange EWS not returning message body for calendar
Specifically I'm not sure how to get a calendar message's body in a query.
My XML query is:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<m:FindItem Traversal="Shallow" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ItemShape>
<t:BaseShape>IdOnly</t:BaseShape>
<t:AdditionalProperties>
<t:FieldURI FieldURI="item:Body"/>
<t:FieldURI FieldURI="calendar:Start"/>
<t:FieldURI FieldURI="calendar:End"/>
<t:FieldURI FieldURI="calendar:Location"/>
<t:FieldURI FieldURI="item:Attachments"/>
</t:AdditionalProperties>
</m:ItemShape>
<m:CalendarView EndDate="2016-07-08T00:00:00Z" MaxEntriesReturned="999999" StartDate="2016-07-07T00:00:00Z"/>
<m:ParentFolderIds>
<t:DistinguishedFolderId Id="calendar"/>
</m:ParentFolderIds>
</m:FindItem>
</s:Body>
</s:Envelope>
But I seem to be getting an error with:
<t:FieldURI FieldURI="item:Body"/>
Error Message
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" MajorVersion="15" MinorVersion="1" MajorBuildNumber="534" MinorBuildNumber="21"/>
</s:Header>
<s:Body>
<m:FindItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:FindItemResponseMessage ResponseClass="Error">
<m:MessageText>Property is not valid for this operation.</m:MessageText>
<m:ResponseCode>ErrorInvalidPropertyForOperation</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
<m:MessageXml>
<t:FieldURI FieldURI="item:Body"/>
</m:MessageXml>
</m:FindItemResponseMessage>
</m:ResponseMessages>
</m:FindItemResponse>
</s:Body>
</s:Envelope>
I've looked over the API Here:
https://msdn.microsoft.com/en-us/library/office/aa494315(v=exchg.150).aspx
And I think I must be missing something simple. Is there a way using a specific field based query to get a calendar body?
Thanks

The FindItem operation doesn't return the Body, Attendees and other complex/large properties see https://blogs.msdn.microsoft.com/vikas/2007/07/26/ews-why-does-not-finditem-return-all-the-fields-you-expected/ .
So you need to take the ItemId you get from the FindItem Request and then either make a single GetItem Request https://msdn.microsoft.com/en-us/library/office/aa564509(v=exchg.150).aspx or if you need it for multiple Items batch the GetItem Request together for efficiency.

Related

EWS. FindItem operation. How to map response data to the request?

In my app I need to look for messages with certain custom properties. I'm using FindItem operation. This is the XML of my request:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mes="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:typ="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<typ:RequestServerVersion Version="Exchange2010_SP2" />
</soap:Header>
<soap:Body>
<mes:FindItem Traversal="Shallow">
<mes:ItemShape>
<typ:BaseShape>IdOnly</typ:BaseShape>
</mes:ItemShape>
<mes:Restriction>
<typ:Or>
<typ:IsEqualTo>
<typ:ExtendedFieldURI PropertySetId="36603a56-9a21-4e9d-b4b7-6eb13876716a" PropertyName="OriginalId" PropertyType="String" />
<typ:FieldURIOrConstant>
<typ:Constant Value="F33A7D78-5FCB-492E-AE98-D7E1CBB379C7" />
</typ:FieldURIOrConstant>
</typ:IsEqualTo>
<typ:IsEqualTo>
<typ:ExtendedFieldURI PropertySetId="36603a56-9a21-4e9d-b4b7-6eb13876716a" PropertyName="OriginalId" PropertyType="String" />
<typ:FieldURIOrConstant>
<typ:Constant Value="hello-world-135" />
</typ:FieldURIOrConstant>
</typ:IsEqualTo>
<typ:IsEqualTo>
<typ:ExtendedFieldURI PropertySetId="36603a56-9a21-4e9d-b4b7-6eb13876716a" PropertyName="OriginalId" PropertyType="String" />
<typ:FieldURIOrConstant>
<typ:Constant Value="9BA188D5-EC35-4E46-AA0B-1C902F6EE70E" />
</typ:FieldURIOrConstant>
</typ:IsEqualTo>
</typ:Or>
</mes:Restriction>
<mes:ParentFolderIds>
<typ:DistinguishedFolderId Id="sentitems" />
</mes:ParentFolderIds>
</mes:FindItem>
</soap:Body>
</soap:Envelope>
So I'm looking for three messages as you can see. One of them (second one) doesn't exist. So in the response I expected to receive some indication that no data for this specific message was found. But this is what I get in the response:
<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" MajorVersion="15" MinorVersion="0" MajorBuildNumber="1365" MinorBuildNumber="1" Version="V2_23" />
</s:Header>
<s:Body xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<m:FindItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:FindItemResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:RootFolder TotalItemsInView="2" IncludesLastItemInRange="true">
<t:Items>
<t:Message>
<t:ItemId Id="AAMkADE3MTJkZWNlLTZiYWYtNDY4Yi1hNmM3LWU2MzY2ZDZjYWNhMQBGAAAAAACoXti5FFu8TJNLLS5k9vC8BwAcJDq8WkSCQ77jdOtyazgnAAAAAAEJAAAcJDq8WkSCQ77jdOtyazgnAAEJ1zgKAAA=" ChangeKey="CQAAABYAAAAcJDq8WkSCQ77jdOtyazgnAAEJ7PHv" />
</t:Message>
<t:Message>
<t:ItemId Id="AAMkADE3MTJkZWNlLTZiYWYtNDY4Yi1hNmM3LWU2MzY2ZDZjYWNhMQBGAAAAAACoXti5FFu8TJNLLS5k9vC8BwAcJDq8WkSCQ77jdOtyazgnAAAAAAEJAAAcJDq8WkSCQ77jdOtyazgnAAEJ1zgJAAA=" ChangeKey="CQAAABYAAAAcJDq8WkSCQ77jdOtyazgnAAEJ7PHs" />
</t:Message>
</t:Items>
</m:RootFolder>
</m:FindItemResponseMessage>
</m:ResponseMessages>
</m:FindItemResponse>
</s:Body>
</s:Envelope>
Only two messages and no indication which ones in the request they belong to. So how am I supposed to map the two found messages to the data in request? Are the messages in the response actually 1 and 2? 2 and 3? or 1 and 3 (which is true in this case)? Do you see my confusion? Obviously I'm doing something wrong. There should be a way to map the data easily. How should I build the request the proper way?
UPDATE:
What I also tried was making a separate FindItem node for each message but unfortunately this didn't work either. The response contained data only for the first item
Your ItemShape element caninclude AdditionalProperties element where you can specify your custom properties, such as "OriginalId".

Specifying multiple ids (AlternateId ) in the ConvertId EWS request?

I was under an impression that I can pass multiple ids in the ConvertId request. If I send the following request with two ids (they happen to be folder and its child message), I only get one id back.
Sure sounds like a bug...
Request:
<?xml version="1.0" encoding="ISO-8859-1"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010"/>
</soap:Header>
<soap:Body>
<m:ConvertId DestinationFormat="EwsId">
<m:SourceIds>
<AlternateId Format="EntryId" Id="AAAAAF6BdU8APhVJsGWfKuqS58IBAMfPIwTHe/ZFheiJLdb/e6wAAAAAAQwAAA==" Mailbox="user#domain.demo"/>
<AlternateId Format="EntryId" Id="AAAAAF6BdU8APhVJsGWfKuqS58IHAMfPIwTHe/ZFheiJLdb/e6wAAAAAAQwAAEp86F7RqydMniCqPL+oKLEAAeNW8FMAAA==" Mailbox="user#domain.demo"/>
</m:SourceIds>
</m:ConvertId>
</soap:Body>
</soap:Envelope>
And the response is
<?xml version="1.0" encoding="ISO-8859-1"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" Version="V2018_01_08" MinorBuildNumber="31" MajorBuildNumber="1228" MinorVersion="20" MajorVersion="15"/>
</s:Header>
<s:Body>
<m:ConvertIdResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
<m:ResponseMessages>
<m:ConvertIdResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:AlternateId Mailbox="user#domain.demo" Id="AQMkAGU2ZWM5ZTQwLTk0MjMtNDY3NS1iZWI5LWQ4NTA0MDhmM2U0OQBGAAADXoF1TwA+FUmwZZ8q6pLnwgcAx88jBMd79kWF6Ikt1v97rAAAAgEMAAAASnzoXtGrJ0yeIKo8v6gosQAB41bwUwAAAA==" Format="EwsId" xsi:type="t:AlternateIdType"/>
</m:ConvertIdResponseMessage>
</m:ResponseMessages>
</m:ConvertIdResponse>
</s:Body>
</s:Envelope>
EDIT:
An example of two ids (two messages) request worling as expected.
Request:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010"/>
</soap:Header>
<soap:Body>
<ConvertId xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
DestinationFormat="EwsId">
<SourceIds>
<t:AlternateId Format="EntryId"
Id="AAAAAF6BdU8APhVJsGWfKuqS58IHAMfPIwTHe/ZFheiJLdb/e6wAAAAAAQwAAEp86F7RqydMniCqPL+oKLEAAiLXM0AAAA=="
Mailbox="user#domain.demo"/>
<t:AlternateId Mailbox="user#domain.demo"
Id="AAAAAF6BdU8APhVJsGWfKuqS58IHAMfPIwTHe/ZFheiJLdb/e6wAAAAAAQwAAEp86F7RqydMniCq PL+oKLEAAiC+eEMAAA=="
Format="EntryId"/>
</SourceIds>
</ConvertId>
Response:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="1273" MinorBuildNumber="26" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header><s:Body><m:ConvertIdResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:ConvertIdResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:AlternateId xsi:type="t:AlternateIdType" Format="EwsId" Id="AQMkAGU2ZWM5ZTQwLTk0MjMtNDY3NS1iZWI5LWQ4NTA0MDhmM2U0OQBGAAADXoF1TwA+FUmwZZ8q6pLnwgcAx88jBMd79kWF6Ikt1v97rAAAAgEMAAAASnzoXtGrJ0yeIKo8v6gosQACItczQAAAAA==" Mailbox="user#domain.demo"/>
</m:ConvertIdResponseMessage>
<m:ConvertIdResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:AlternateId xsi:type="t:AlternateIdType" Format="EwsId" Id="AQMkAGU2ZWM5ZTQwLTk0MjMtNDY3NS1iZWI5LWQ4NTA0MDhmM2U0OQBGAAADXoF1TwA+FUmwZZ8q6pLnwgcAx88jBMd79kWF6Ikt1v97rAAAAgEMAAAASnzoXtGrJ0yeIKo8v6gosQACIL54QwAAAA==" Mailbox="user#domain.demo"/>
</m:ConvertIdResponseMessage>
</m:ResponseMessages>
</m:ConvertIdResponse>
</s:Body>
</s:Envelope>
Corrections
So, consolidating our exchange so it can be seen as the answer to date.
As per the sanity testing of this method by myself and Dmitry Streblechenko (the OP). In leveraging this method, multiples are allowed.
For example: only one type (messages) or another (folders) is allowed at the same time.

How to retrieve all changed folders from the root public folder via EWS?

I need to get all public folders when a user changes permissions or items in a folder. How to do it? I can not find the proper answer in the documentation.
I only found this:
POST outlook.office365.com/EWS/Exchange.asmx
?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013" />
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:PrimarySmtpAddress>test#test_test.onmicrosoft.com</t:PrimarySmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<m:SyncFolderHierarchy>
<m:FolderShape>
<t:BaseShape>IdOnly</t:BaseShape>
</m:FolderShape>
<m:SyncFolderId>
<t:DistinguishedFolderId Id="publicfoldersroot" />
</m:SyncFolderId>
</m:SyncFolderHierarchy>
</soap:Body>
</soap:Envelope>
and the response is:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="1207" MinorBuildNumber="28" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
<m:SyncFolderHierarchyResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:SyncFolderHierarchyResponseMessage ResponseClass="Error">
<m:MessageText>The root of a folder hierarchy synchronization cannot be set to the id of a public folder. Use FindFolder to synchronize the public folder hierarchy.</m:MessageText>
<m:ResponseCode>ErrorInvalidOperation</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
<m:SyncState/>
<m:IncludesLastFolderInRange>true</m:IncludesLastFolderInRange>
</m:SyncFolderHierarchyResponseMessage>
</m:ResponseMessages>
</m:SyncFolderHierarchyResponse>
</s:Body>
</s:Envelope>
As you can see it does not work.

How to properly create/update public folder via EWS using admin impersonation?

I cannot create any public folder in case when I set proper permission (through WebUI) to that user (in my case admin).
But when I try to update public folder`s 'EffectiveRights' to add permission level to that user I cannot do it. Which request I need to send to update user permission level on public folder or add proper 'EffectiveRights' on that public folder?
Example of the request:
POST outlook.office365.com/EWS/Exchange.asmx
Content-Type:text/xml; charset=utf-8
Accept:text/xml; charset=utf-8
BODY
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013_SP1" />
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:PrimarySmtpAddress>test#test_test.onmicrosoft.com</t:PrimarySmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<UpdateFolder xmlns="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<FolderChanges>
<t:FolderChange>
<t:DistinguishedFolderId Id="publicfoldersroot" />
<t:Updates>
<t:SetFolderField>
<t:FieldURI FieldURI="folder:EffectiveRights"/>
<t:Folder>
<t:EffectiveRights>
<t:CreateAssociated>false</t:CreateAssociated>
<t:CreateContents>true</t:CreateContents>
<t:CreateHierarchy>false</t:CreateHierarchy>
<t:Delete>false</t:Delete>
<t:Modify>false</t:Modify>
<t:Read>true</t:Read>
</t:EffectiveRights>
</t:Folder>
</t:SetFolderField>
</t:Updates>
</t:FolderChange>
</FolderChanges>
</UpdateFolder>
</soap:Body>
</soap:Envelope>
and the response is:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="1164" MinorBuildNumber="25" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
<m:UpdateFolderResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:UpdateFolderResponseMessage ResponseClass="Error">
<m:MessageText>Set action is invalid for property.</m:MessageText>
<m:ResponseCode>ErrorInvalidPropertySet</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
<m:MessageXml>
<t:FieldURI FieldURI="folder:EffectiveRights"/>
</m:MessageXml>
<m:Folders/>
</m:UpdateFolderResponseMessage>
</m:ResponseMessages>
</m:UpdateFolderResponse>
</s:Body>
</s:Envelope>
another one example:
POST outlook.office365.com/EWS/Exchange.asmx
Content-Type:text/xml; charset=utf-8
Accept:text/xml; charset=utf-8
BODY
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages"
xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2013_SP1" />
<t:ExchangeImpersonation>
<t:ConnectingSID>
<t:PrimarySmtpAddress>test#test_test.onmicrosoft.com</t:PrimarySmtpAddress>
</t:ConnectingSID>
</t:ExchangeImpersonation>
</soap:Header>
<soap:Body>
<m:UpdateFolder>
<m:FolderChanges>
<t:FolderChange>
<t:FolderId Id="AAEuAAAAAAAaRHOQqmYRzZvIAKoAL8RaAwCOXNGsJPKoS5iTrqfBNvbzAACDSr4rAAA=" />
<t:Updates>
<t:SetFolderField>
<t:FieldURI FieldURI="folder:PermissionSet" />
<t:Folder>
<t:PermissionSet>
<t:Permissions>
<t:Permission>
<t:UserId>
<t:PrimarySmtpAddress>test#test_test.onmicrosoft.com</t:PrimarySmtpAddress>
</t:UserId>
<t:PermissionLevel>Editor</t:PermissionLevel>
</t:Permission>
</t:Permissions>
</t:PermissionSet>
</t:Folder>
</t:SetFolderField>
</t:Updates>
</t:FolderChange>
</m:FolderChanges>
</m:UpdateFolder>
</soap:Body>
</soap:Envelope>
and the response:
<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="15" MinorVersion="20" MajorBuildNumber="1143" MinorBuildNumber="18" Version="V2018_01_08" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</s:Header>
<s:Body>
<m:UpdateFolderResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:UpdateFolderResponseMessage ResponseClass="Error">
<m:MessageText>Access is denied. Check credentials and try again., Underlying MAPI stream threw exception</m:MessageText>
<m:ResponseCode>ErrorAccessDenied</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
<m:Folders/>
</m:UpdateFolderResponseMessage>
</m:ResponseMessages>
</m:UpdateFolderResponse>
</s:Body>
</s:Envelope>
Because your trying to create folders in publicfoldersroot no user has rights by default to do that (this is to stop people messing up the Public Folder root). So if you want your user test#test_test.onmicrosoft.com you would need to first grant them rights to do that on the Root folder either using the EAC or Add-PublicFolderclientPermissions. I would suggest you first create a folder in the Root using the EAC and then get your code to create child folders of that, from a development point of view this is easier to cleanup when you need to delete everything and test again then trying to clear the whole root hierarchy each time.
Also only you second example will work because EffectiveRights is a calculate property so can't be updated, all you can do is update the underlying DACL of the folder which is what you second request is doing

Exchange web service (EWS) says "Accees denied" when I try to delete calendar event created by me

I am trying to delete a calendar event that I have created a while ago.
Case 1:
I call EWS to create a calendar event using credentials of domain user broom#infusion.com in some room providing email address of the room and then I get ID of the event
Then I delete the event by calling EWS and providing Id and ChangeKey, and all is fine - meeting is deleted
Case 2
I create event the same way like in Case 1
I get list of calendar events for this room. Now ID of the event has HexEntryId format. So I use ConvertId method to convert it to EwsLegacyId required by DeleteItem method
I call DeleteItem method with ID of event provided by ConvertId method, but without ChangeKey (I don't have it)
DeleteItemResponse says "Access is denied. Check credentials and try again."
Why can I remove event in Case 1 and I cannot in Case 2? What should I do to delete the event (like in Case 2)?
Here are details of request and responses:
Case 1:
I call EWS to create a calendar event using credentials of domain user broom#mycompany.com in some room by providing email address of the room – a meeting like this:
<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>
<CreateItem xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" SendMeetingInvitations=\"SendToAllAndSaveCopy\" >
<SavedItemFolderId>
<t:DistinguishedFolderId Id=\"calendar\"/>
</SavedItemFolderId>
<Items>
<t:CalendarItem xmlns=\"http://schemas.microsoft.com/exchange/services/2006/types\">
<Subject>Instant Meeting</Subject>
<Body BodyType=\"Text\">Generated By mycompany Room Booker</Body>
<ReminderIsSet>false</ReminderIsSet>
<ReminderMinutesBeforeStart>60</ReminderMinutesBeforeStart>
<Start>2015-10-01T10:26:02.000Z</Start>
<End>2015-10-01T10:41:02.000Z</End>
<IsAllDayEvent>false</IsAllDayEvent>
<LegacyFreeBusyStatus>Busy</LegacyFreeBusyStatus>
<RequiredAttendees>
<Attendee>
<Mailbox>
<EmailAddress>brdmlt-mainbrd#mycompany.com</EmailAddress>
</Mailbox>
</Attendee>
</RequiredAttendees>
</t:CalendarItem>
</Items>
</CreateItem>
</soap:Body>
</soap:Envelope>
then meeting is accepted and I get ItemID like:
state.ChangeKey: "DwAAABYAAADw3LMNr7pMRqtEFFAbr0MeAAAAhxz0"
state.Id: "AAASAGJyb29tQGluZnVzaW9uLmNvbQBGAAAAAAB5mlhabHe9S4yVHCob9IbcBwDw3LMNr7pMRqtEFFAbr0MeAAAAOdnlAADw3LMNr7pMRqtEFFAbr0MeAAAAhrdWAAA="
Then I delete the event by calling EWS and providing Id and ChangeKey:
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:m=\"http://schemas.microsoft.com/exchange/services/2006/messages\" xmlns:t=\"http://schemas.microsoft.com/exchange/services/2006/types\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">
<soap:Header/>
<soap:Body>
<m:DeleteItem DeleteType=\"MoveToDeletedItems\" SendMeetingCancellations=\"SendToAllAndSaveCopy\">
<m:ItemIds>
<t:ItemId Id=\"AAASAGJyb29tQGluZnVzaW9uLmNvbQBGAAAAAAB5mlhabHe9S4yVHCob9IbcBwDw3LMNr7pMRqtEFFAbr0MeAAAAOdnlAADw3LMNr7pMRqtEFFAbr0MeAAAAhrdWAAA=\" ChangeKey=\"DwAAABYAAADw3LMNr7pMRqtEFFAbr0MeAAAAhxz0\"/>
</m:ItemIds>
</m:DeleteItem>
</soap:Body>
</soap:Envelope>
and all is fine. The event is deleted.
Case 2:
But when I create event the same way and get response like this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="14" MinorVersion="3" MajorBuildNumber="235" MinorBuildNumber="1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<m:CreateItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:CreateItemResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:Items>
<t:CalendarItem>
<t:ItemId Id="AAASAGJyb29tQGluZnVzaW9uLmNvbQBGAAAAAAB5mlhabHe9S4yVHCob9IbcBwDw3LMNr7pMRqtEFFAbr0MeAAAAOdnlAADw3LMNr7pMRqtEFFAbr0MeAAAAhrdYAAA=" ChangeKey="DwAAABYAAADw3LMNr7pMRqtEFFAbr0MeAAAAhx08" />
</t:CalendarItem>
</m:Items>
</m:CreateItemResponseMessage>
</m:ResponseMessages>
</m:CreateItemResponse>
</s:Body>
</s:Envelope>
and when I list calendar events for this room like below:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010_SP2" />
</soap:Header>
<soap:Body>
<GetUserAvailabilityRequest xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<TimeZone xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
<Bias>300</Bias>
<StandardTime>
<Bias>0</Bias>
<Time>02:0:00</Time>
<DayOrder>1</DayOrder>
<Month>10</Month>
<DayOfWeek>Sunday</DayOfWeek>
</StandardTime>
<DaylightTime>
<Bias>-60</Bias>
<Time>02:00:00</Time>
<DayOrder>2</DayOrder>
<Month>3</Month>
<DayOfWeek>Sunday</DayOfWeek>
</DaylightTime>
</TimeZone>
<MailboxDataArray>
<MailboxData xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
<Email>
<Name/>
<Address>BRDHOU-MAINBRD#mycompany.com</Address>
<RoutingType>SMTP</RoutingType>
</Email>
<AttendeeType>Room</AttendeeType>
<ExcludeConflicts>false</ExcludeConflicts>
</MailboxData>
</MailboxDataArray>
<FreeBusyViewOptions xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
<TimeWindow>
<StartTime>2015-10-01T06:34:09</StartTime>
<EndTime>2015-10-01T23:59:59</EndTime>
</TimeWindow>
<MergedFreeBusyIntervalInMinutes>60</MergedFreeBusyIntervalInMinutes>
<RequestedView>Detailed</RequestedView>
</FreeBusyViewOptions>
</GetUserAvailabilityRequest>
</soap:Body>
</soap:Envelope>
I get response with IDs in some other format (HexEntryId):
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="14" MinorVersion="3" MajorBuildNumber="235" MinorBuildNumber="1" Version="Exchange2010_SP2" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GetUserAvailabilityResponse xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
<FreeBusyResponseArray>
<FreeBusyResponse>
<ResponseMessage ResponseClass="Success">
<ResponseCode>NoError</ResponseCode>
</ResponseMessage>
<FreeBusyView>
<FreeBusyViewType xmlns="http://schemas.microsoft.com/exchange/services/2006/types">Detailed</FreeBusyViewType>
<CalendarEventArray xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
<CalendarEvent>
<StartTime>2015-10-01T06:36:51</StartTime>
<EndTime>2015-10-01T06:51:51</EndTime>
<BusyType>Busy</BusyType>
<CalendarEventDetails>
<ID>00000000B23AEBAC6379B34DBBBA0B525D2BBFD70700C26EC63E0E9E2A49B110258061BF491D000000FDECCA0000C26EC63E0E9E2A49B110258061BF491D0000D9385B8C0000</ID>
<Subject>Boardroom Tablet </Subject>
<IsMeeting>true</IsMeeting>
<IsRecurring>false</IsRecurring>
<IsException>false</IsException>
<IsReminderSet>false</IsReminderSet>
<IsPrivate>false</IsPrivate>
</CalendarEventDetails>
</CalendarEvent>
</CalendarEventArray>
<WorkingHours xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
<TimeZone>
<Bias>300</Bias>
<StandardTime>
<Bias>0</Bias>
<Time>02:00:00</Time>
<DayOrder>1</DayOrder>
<Month>11</Month>
<DayOfWeek>Sunday</DayOfWeek>
</StandardTime>
<DaylightTime>
<Bias>-60</Bias>
<Time>02:00:00</Time>
<DayOrder>2</DayOrder>
<Month>3</Month>
<DayOfWeek>Sunday</DayOfWeek>
</DaylightTime>
</TimeZone>
<WorkingPeriodArray>
<WorkingPeriod>
<DayOfWeek>Monday Tuesday Wednesday Thursday Friday</DayOfWeek>
<StartTimeInMinutes>480</StartTimeInMinutes>
<EndTimeInMinutes>1140</EndTimeInMinutes>
</WorkingPeriod>
</WorkingPeriodArray>
</WorkingHours>
</FreeBusyView>
</FreeBusyResponse>
</FreeBusyResponseArray>
</GetUserAvailabilityResponse>
</s:Body>
</s:Envelope>
To be able to call DeleteItem I need this Id in EwsLegacyId format instead of HexEntryId format, so I call ConvertId method:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010" />
</soap:Header>
<soap:Body>
<m:ConvertId DestinationFormat="EwsLegacyId">
<m:SourceIds>
<t:AlternateId Format="HexEntryId" Id="00000000B23AEBAC6379B34DBBBA0B525D2BBFD70700C26EC63E0E9E2A49B110258061BF491D000000FDECCA0000C26EC63E0E9E2A49B110258061BF491D0000D9385B940000" Mailbox="BRDNYC-Collab2#mycompany.com" />
</m:SourceIds>
</m:ConvertId>
</soap:Body>
</soap:Envelope>
and I get
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="14" MinorVersion="3" MajorBuildNumber="235" MinorBuildNumber="1" Version="Exchange2010_SP2" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<m:ConvertIdResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:ConvertIdResponseMessage ResponseClass="Success">
<m:ResponseCode>NoError</m:ResponseCode>
<m:AlternateId xsi:type="t:AlternateIdType" Format="EwsLegacyId" Id="AAAbAEJSRE5ZQy1Db2xsYWIyQGluZnVzaW9uLmNvbQBGAAAAAACyOuusY3mzTbu6C1JdK7/XBwDCbsY+Dp4qSbEQJYBhv0kdAAAA/ezKAADCbsY+Dp4qSbEQJYBhv0kdAADZOFuUAAA=" Mailbox="BRDNYC-Collab2#mycompany.com" />
</m:ConvertIdResponseMessage>
</m:ResponseMessages>
</m:ConvertIdResponse>
</s:Body>
</s:Envelope>
And when I try to call DeleteItem on this Id like this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header/>
<soap:Body>
<m:DeleteItem DeleteType="MoveToDeletedItems" SendMeetingCancellations="SendToAllAndSaveCopy">
<m:ItemIds>
<t:ItemId Id="AAAbAEJSRE5ZQy1Db2xsYWIyQGluZnVzaW9uLmNvbQBGAAAAAACyOuusY3mzTbu6C1JdK7/XBwDCbsY+Dp4qSbEQJYBhv0kdAAAA/ezKAADCbsY+Dp4qSbEQJYBhv0kdAADZOFuUAAA=" />
</m:ItemIds>
</m:DeleteItem>
</soap:Body>
</soap:Envelope>
I get
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<h:ServerVersionInfo MajorVersion="14" MinorVersion="3" MajorBuildNumber="235" MinorBuildNumber="1" xmlns:h="http://schemas.microsoft.com/exchange/services/2006/types" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
</s:Header>
<s:Body>
<m:DeleteItemResponse xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<m:ResponseMessages>
<m:DeleteItemResponseMessage ResponseClass="Error">
<m:MessageText>Access is denied. Check credentials and try again.</m:MessageText>
<m:ResponseCode>ErrorAccessDenied</m:ResponseCode>
<m:DescriptiveLinkKey>0</m:DescriptiveLinkKey>
</m:DeleteItemResponseMessage>
</m:ResponseMessages>
</m:DeleteItemResponse>
</s:Body>
</s:Envelope>
"Accees denied. Check credentials and try again"
In Case 1 your deleting the Appointment from your calendar which you have Full Access to. In Case2 it looks like your trying to delete the appointment from the Room Mailbox which you may or may not have Full rights to (the default is read only even if you are the organizer of the appointment its the calendar itself you would need rights to). In the case where you where the organizer of said appointment you would be better to just cancel the appointment in your calendar and send the cancellation through to the Room mailbox and let the auto-accept on the Room mailbox process and perform the delete that way or you would need to assign the mailbox that is trying to do the Delete Full access to the Room mailbox in question.
cheers
Glen

Resources