Previous Page Arrow Next Page Arrow

9.1 Update Example

A resource is updated by sending a PUT request with an Atom <entry> to its URL. For example:

PUT /sdata/myApp/myContract/-/salesOrders('43661')
Content-Type: application/atom+xml; type=entry
If-Match: 2nXz9DZYR2pqmcXi/ZCbYA==
 
<entry xmlns:sdata="http://schemas.sage.com/sdata/2008/1" 
       xmlns:http="http://schemas.sage.com/sdata/http/2008/1" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.w3.org/2005/Atom">
  <id>http://www.example.com/sdata/myApp/myContract/-/salesOrders('43661')</id>
  <title>Sales Order 43661</title>
  <updated>2008-03-31T13:46:45Z</updated>
  <sdata:payload>
    <salesOrder xmlns="http://schemas.sage.com/myContract">
      <orderNumber>43661</orderNumber>
      <orderDate>2008-03-31</orderDate>
      <shipDate>2008-04-05</shipDate>
      <contact sdata:key="216" />
      <subTotal>202.70</subTotal>
    </salesOrder>
  </sdata:payload>
  <http:ifMatch>2nXz9DZYR2pqmcXi/ZCbYA==</http:ifMatch>
</entry>

Some HTTP infrastructures do not support the PUT method. In such cases, the request SHOULD be submitted as a POST with an additional X-HTTP-Method-Override header set to PUT. The request becomes:

POST /sdata/myApp/myContract/-/salesOrders('43661')
X-HTTP-Method-Override: PUT
...

This request changes the shipDate property of the sales order resource.

If the operation succeeds, the service provider sends a response such as:

200 OK
Content-Type: application/atom+xml; type=entry
ETag: STFtZgHEkPz7TyH98YEmWA==
 
<entry xmlns:sdata="http://schemas.sage.com/sdata/2008/1" 
       xmlns:http="http://schemas.sage.com/sdata/http/2008/1" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns="http://www.w3.org/2005/Atom">
  <id>http://www.example.com/sdata/myApp/myContract/-/salesOrders('43661')</id>
  <title>Sales Order 43661</title>
  <updated>2008-03-31T13:46:45Z</updated>

  <link rel="self" type="application/atom+xml; type=entry" title="Refresh"
        href="http://www.example.com/sdata/myApp/myContract/-/salesOrders('43661')" />
  <link rel="edit" type="application/atom+xml; type=entry" title="Edit"
        href="http://www.example.com/sdata/myApp/myContract/-/salesOrders('43661')" />
  <link rel="http://schemas.sage.com/sdata/link-relations/schema" 
        type="application/xml" title="Schema" 
        href="http://www.example.com/sdata/myApp/myContract/-/salesOrders/$schema?version=5" />
  <link rel="http://schemas.sage.com/sdata/link-relations/template" 
        type="application/atom+xml; type=entry" title="Template" 
        href="http://www.example.com/sdata/myApp/myContract/-/salesOrders/$template" />
  <link rel="http://schemas.sage.com/sdata/link-relations/post" 
        type="application/atom+xml; type=entry" title="Post" 
        href="http://www.example.com/sdata/myApp/myContract/-/salesOrders" />
  <link rel="http://schemas.sage.com/sdata/link-relations/service" 
        type="application/atom+xml; type=feed" title="Service" 
        href="http://www.example.com/sdata/myApp/myContract/-/salesOrders/$service" />

  <category scheme="http://schemas.sage.com/sdata/categories" 
            term="resource" label="Resource"/>

  <content>1553,1035</content>

  <sdata:payload>
    <salesOrder xmlns="http://schemas.sage.com/myContract"
      sdata:key="43661"
      sdata:url="http://www.example.com/sdata/myApp/myContract/-/salesOrders('43661')"
      sdata:uuid="BE7D7445-7FA4-4c67-AC22-5F6446314771">
      <orderNumber>43661</orderNumber>
      <orderDate>2008-03-31</orderDate>
      <shipDate>2008-04-05</shipDate>
      <contact sdata:key="216"
        sdata:url="http://www.example.com/sdata/myApp/myContract/-/contacts('216')" />
      <subTotal>202.70</subTotal>
    </salesOrder>
  </sdata:payload>
  <http:etag>STFtZgHEkPz7TyH98YEmWA==</http:etag>
</entry>

A few points are worth mentioning here:

  • The ETag value is different in the response. This is normal because the resource has been modified by the request.

  • The ETag value is passed twice and returned twice. Once in the If-Match/ETag header and once in the <http:ifMatch/etag> element. This is normal as we want the request to comply with HTTP rules, which impose the If-Match/ETag headers. And with the SData batching mode, which imposes an <http:ifMatch/etag> element in every entry.

  • The If-Match header and <http:ifMatch/etag> elements are only present if the resource kind handles concurrent modifications with the ETag mechanism. The service consumer can test the supportsETag schema attribute to find out how the service handles concurrent modifications. See Resource Kind Definition section.

SData providers MUST support update operations on all resource kinds that have the sme:canPut flag set to true.

SData providers SHOULD support POST with the X-HTTP-Method-Override header as an alternative to the PUT method.

Previous Page Arrow Next Page Arrow