Search code examples
xmlexchangewebservices

EWS Cannot Update Exchange Contact Phone Numbers with XML


I want to update my exchange contact using Exchange Web Services SOAP API with XML. I have figured out (painstakingly) how to update all of my desired properties except for Phone Numbers.

I followed the pattern used for updating EmailAddresses (since they are both indexed fields). Here is a sample of my XML Request:

<t:SetItemField>
  <t:IndexedFieldURI FieldURI="contacts:PhoneNumber" FieldIndex="BusinessPhone"/>
    <Contact xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
    <PhoneNumbers>
      <Entry key="BusinessPhone">888-777-6666</Entry>
    </PhoneNumbers>
  </Contact>
</t:SetItemField>

And This is the Error message I received back from Exchange:

An internal server error occurred. The operation failed., Key 'PhoneNumbers' not found for type 'Microsoft.Exchange.Services.Core.Types.ContactItemType'

Seeing as the XML for this operation is largely undocumented, I am under the suspicion I am formatting the XML for the PhoneNumber incorrectly.

To anyone who is using the EWS Managed API 2.0, could you perform this operation and trace the XML output so I can see how it's done correctly ?

Any other information leading to a solution is much appreciated!

Thank you


Solution

  • Seeing as the XML for this operation is largely undocumented, I am under the suspicion I am formatting the XML for the PhoneNumber incorrectly.

    There is full documentation for all the XML elements on MSDN https://msdn.microsoft.com/en-us/library/office/aa580675(v=exchg.150).aspx also the protocol documentation has pretty comprehensive coverage https://msdn.microsoft.com/en-us/library/cc425499(v=exchg.80).aspx

    With your request I can reproduce the error your getting to fix it all you need to do is Capitalize the K in key eg

    <Entry key="BusinessPhone">888-777-6666</Entry>  
    

    to

    <Entry Key="BusinessPhone">888-777-6666</Entry>
    

    SOAP (or at least the way it been implemented in EWS) is particular around the case and order of elements. Here's the modified SOAP that work for me

      <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" />
        </soap:Header>
        <soap:Body>
          <m:UpdateItem MessageDisposition="SaveOnly" ConflictResolution="AlwaysOverwrite">
            <m:ItemChanges>
              <t:ItemChange>
                <t:ItemId Id="A...A=" ChangeKey="EQA....Z" />
                <t:Updates>
                <t:SetItemField>
                   <t:IndexedFieldURI FieldURI="contacts:PhoneNumber" FieldIndex="BusinessPhone"/>
                  <Contact xmlns="http://schemas.microsoft.com/exchange/services/2006/types">
                  <PhoneNumbers>
                    <Entry Key="BusinessPhone">888-777-6666</Entry>
                  </PhoneNumbers>
                 </Contact>
                </t:SetItemField>
                </t:Updates>
              </t:ItemChange>
            </m:ItemChanges>
          </m:UpdateItem>
        </soap:Body>
      </soap:Envelope>