Skip to main content

Last updated: 2024-06-07


Update Operation


In this topic:


Overview


The update operation modifies existing objects and their child objects. The request must specify a valid ID for the main (topmost) parent object.


Note: The update operation can update objects by ID only and does not support update by condition.


For a child object, the ID is not required. The child object will be inserted if it does not exist.


Tip: Enclosing update requests in the transaction element is recommended to prevent data issues caused by connection interruptions or other problems.


Basic Usage


The following example request updates the last name and the area code of the preferred phone number for a contact object:


XML
<request version="1.0">
  <header>...</header>
  <update>
    <Contact id="Contact.123.456">
      <LastName>Ackerman</LastName>
      <PreferredPhone>
        <AreaCode>818</AreaCode>
      </PreferredPhone>
    </Contact>
  </update>
</request>

If an object already exists (in this example, the PreferredPhone object), the response looks like this:


XML
<response version="1.0">
  <header>...</header>
  <update>
    <Contact id="Contact.123.456" _status="updated">
      <PreferredPhone id="Phone.123.789" _status="updated"/>
    </Contact>
  </update>
</response>

If the PreferredPhone object does not exist, the response shows that a phone object was inserted:


XML
<response version="1.0">
  <header>...</header>
  <update>
    <Contact id="Contact.123.456" _status="updated">
      <PreferredPhone id="Phone.123.789" _status="inserted" />
    </Contact>
  </update>
</response>

Updating Objects in Arrays


To update an object in a child object array, you must include an ID for that object in the request. Otherwise, you will insert a new object in the array.


Request with ID: The following example request uses an ID to update the area code and phone number of an existing phone number object:


XML
<request version="1.0">
  <header>...</header>
  <update>
    <Contact id="Contact.123.456">
      <Phones>
        <Phone id="Phone.123.789">
          <AreaCode>626</AreaCode>
          <Number>5553550</Number>
        </Phone>
      </Phones>
    </Contact>
  </update>
</request>

The response indicates that the specified object in the child object array was updated:


XML
<response version="1.0">
  <header>...</header>
  <update>
    <Contact id="Contact.123.456">
      <Phones>
        <Phone id="Phone.123.789" _status="updated"/>
      </Phones>
    </Contact>
  </update>
</response>

Request without ID: The following example request does not specify an ID for the phone number:


XML
<request version="1.0">
  <header>...</header>
  <update>
    <Contact id="Contact.123.456">
      <Phones>
        <Phone>
          <AreaCode>626</AreaCode>
          <Number>5553550</Number>
        </Phone>
      </Phones>
    </Contact>
  </update>
</request>

In this instance, the response indicates that a new phone number object was inserted into the database:


XML
<response version="1.0">
  <header>...</header>
  <update>
    <Contact id="Contact.123.456">
      <Phones>
        <Phone id="Phone.123.790" _status="inserted" />
      </Phones>
    </Contact>
  </update>
</response>