Updating physical address of contact
SebastianBecker2 opened this issue · 2 comments
Got some problems updating a contacts physical address.
ews::indexed_property_path path = ews::contact_property_path::physical_addresses_business;
ews::physical_address address(ews::physical_address::key::business, "Street", "City", "State", "Country", "PostalCode");
ews::property prop(path, address);
ews::update up(prop);
This results in the following message:
<?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:m="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010"/>
</soap:Header>
<soap:Body>
<m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite" SendMeetingInvitationsOrCancellations="SendToNone">
<m:ItemChanges>
<t:ItemChange>
<t:ItemId Id="[item_id.id of contact here]" ChangeKey="[item_id.change_key of contact here]"/>
<t:Updates>
<t:SetItemField>
<t:FieldURI FieldURI="contacts:Surname"/>
<t:Contact>
<t:Surname>surname</t:Surname>
</t:Contact>
</t:SetItemField>
<t:SetItemField>
<t:IndexedFieldURI FieldURI="contacts:PhysicalAddresses" FieldIndex="Business"/>
<t:Contact>
<t:PhysicalAddresses>
<t:Entry Key="Business">
<t:Street>Street</t:Street>
<t:City>City</t:City>
<t:State>State</t:State>
<t:CountryOrRegion>Country</t:CountryOrRegion>
<t:PostalCode>PostalCode</t:PostalCode>
</t:Entry>
</t:PhysicalAddresses>
</t:Contact>
</t:SetItemField>
</t:Updates>
</t:ItemChange>
</m:ItemChanges>
</m:UpdateItem>
</soap:Body>
</soap:Envelope>
but the exchange server returns this:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<s:Fault>
<faultcode xmlns:a="http://schemas.microsoft.com/exchange/services/2006/types">a:ErrorInvalidRequest</faultcode>
<faultstring xml:lang="de-DE">Die Anforderung ist ung├╝ltig.</faultstring>
<detail>
<e:ResponseCode xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">ErrorInvalidRequest</e:ResponseCode>
<e:Message xmlns:e="http://schemas.microsoft.com/exchange/services/2006/errors">Die Anforderung ist ung├╝ltig.</e:Message>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
Updating other properties of a contact isn't a problem. Event indexed properties like phone_numbers or something works fine.
But physical addresses are the only index property that consists of more than a single value.
And I have a hard time finding something useful in Microsofts ews docu regarding updating those values. The examples are so dumped down that they are barely useful at all.
Yes, not much info available out there. Only for the basics. I guess most of knowledge is behind corporate walls. I was always quickest when playing around with EWS Editor and writing XML payload by hand to try things out.
Problem solved. The issue was mainly the property path. The ones defined in the library are bit off.
When updating a physical address of a contact, you have to update each element on it's own.
For example the path "contacts:PhysicalAddress:Street" with the index "Business" to update the street of the business address. And it needs a physical_address object with the "Business" key and the street.
Something like the following:
ews::indexed_property_path path = ews::contact_property_path::physical_address::business::city;
ews::physical_address address(ews::physical_address::key::business, "", "MyCity", "", "", "");
ews::property prop(path, address);
service.update_item(id, prop);
I will make a pull request when I'm done with updating the extended properties from #142