Change a Content Item

Once your client application has located a content item you are interested in, it can retrieve it, modify it and submit the changed version. The example in this section shows how to make the simplest of changes: a simple change to the title of a content item.

The first objective is to retrieve the content item:

curl -u user:password -X GET http://host-ip-address/webservice/escenic/content/43

The content item is returned as an Atom entry resource:

<entry xmlns="http://www.w3.org/2005/Atom"
       xmlns:app="http://www.w3.org/2007/app" 
       xmlns:metadata="http://xmlns.escenic.com/2010/atom-metadata" 
       xmlns:dcterms="http://purl.org/dc/terms/">  
  <id>http://host-ip-address/webservice/escenic/content/43</id>
  <title type="text">Test</title>  
  <app:edited>2010-06-23T09:09:50.654Z</app:edited> 
  <dcterms:created>2010-06-22T10:22:20.000Z</dcterms:created>
  <author>
    <name>demo Administrator</name>  
    <uri>http://host-ip-address/webservice/escenic/person/2</uri>
  </author>  
  <dcterms:identifier>4</dcterms:identifier>  
  <metadata:reference source="ece-auto-gen" sourceid="6d7203c9-27d5-4fce-b14a-a466ead83875"/> 
  <link rel="http://www.escenic.com/types/relation/home-section" 
        href="http://host-ip-address/webservice/escenic/section/4" 
        title="New Articles" 
        type="application/atom+xml; type=entry"/>
  <link href="http://wrk-ermo:12345/demo/incoming/article4.ece" 
        rel="alternate"/>  
  <link href="http://host-ip-address/webservice/escenic/lock/article/43" 
        rel="http://www.escenic.com/types/relation/lock"/>  
  <link rel="http://www.escenic.com/types/relation/publication" 
        href="http://host-ip-address/webservice/escenic/publication/demo" 
        title="demo" 
        type="application/atom+xml; type=entry"/>  
  <metadata:creator>
    <name>demo Administrator</name>
  </metadata:creator>  o
  <metadata:publication href="http://host-ip-address/webservice/escenic/publication/demo">
    <link rel="http://www.escenic.com/types/relation/home-section" 
          href="http://host-ip-address/webservice/escenic/section/4" 
          title="New Articles" 
          type="application/atom+xml; type=entry"/> 
    <link rel="http://www.escenic.com/types/relation/section" 
          href="http://host-ip-address/webservice/escenic/section/4" 
          title="New Articles" 
          type="application/atom+xml; type=entry"/>
  </metadata:publication> 
  <link href="http://host-ip-address/webservice/escenic/content/43" rel="edit"/>  
  <link href="http://host-ip-address/webservice/escenic/content/43" rel="self"/>  
  <content type="application/vnd.escenic.payload+xml"> 
    <vdf:payload xmlns:vdf="http://www.escenic.com/types" 
         model="http://host-ip-address/webservice/content-descriptions/another">  
      <vdf:field name="BODY">
        <vdf:value> 
            <div xmlns="http://www.w3.org/1999/xhtml"> 
              <p>This is a test</p>
            </div> 
        </vdf:value>
      </vdf:field>  
    </vdf:payload>  
  </content>  
</entry>

Your client application can now modify the title of the content item (highlighted in the above listing). If you are following this example using curl from the command line, you can simple copy the returned entry into a text editor and manually change the content of the title element:

  <title type="text">Edited Title</title>

and save the results to a file (called my-edited-item.xml, for example).

In order to submit the updated content item, you must PUT the file you have saved to the same URI from which it was retrieved:

curl --include -u user:password -X PUT -H "If-Match: *" -H "Content-Type: application/atom+xml" \
> http://host-ip-address/webservice/escenic/content/4 --upload-file my-edited-article.xml
HTTP/1.1 100 Continue

HTTP/1.1 200 OK
Date: Thu, 24 Jun 2010 09:23:24 GMT
Content-Type: application/atom+xml;type=entry
Content-Length: 0
Server: Jetty(6.1.19)

In order for the PUT operation to work, you must specify two HTTP headers as shown above:

Content-Type: application/atom+xml

You must specify the content type of the data you are uploading.

If-Match: *

The If-Match header value * is used here for reasons of simplicity. It is acceptable to use it for test and demonstration purposes, but should never be used in a production system. For more information about this header and what it does, see Optimistic Concurrency.

If you're using curl, it's a good idea to specify --include with PUT operations: curl will then output the response header returned from the web service as shown above, and you can verify whether or not the operation was successful:

  • A response code in the 2xx range indicates success.

  • A response code in the 4xx range means that you made an invalid edit and the server won’t accept your modification.

  • A response code in the 5xx range means there is a server error.

Submitting a change in this way may not work if the resource you are attempting to modify is already locked by another client application. For more information about this and about how locking works, see Lock a Content Item.