Create a Content Item
To create a new content item, your client application must create an Atom entry resource containing a Viz Data Format (VDF) payload document:
<?xml version="1.0"?> <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/"> <title type="text">My first item</title> <app:control> <app:draft>yes</app:draft> </app:control> <content type="application/vnd.vizrt.payload+xml"> <vdf:payload xmlns:vdf="http://www.vizrt.com/types" model="http://host-ip-address/webservice/escenic/publication/pub-name/model/content-type/content-type-name"> <vdf:field name="title"> <vdf:value>My first item</vdf:value> </vdf:field> <vdf:field name="summary"> <vdf:value>This is a summary</vdf:value> </vdf:field> <vdf:field name="body"> <vdf:value> <div xmlns="http://www.w3.org/1999/xhtml"> <p>This is the body!</p> </div> </vdf:value> </vdf:field> </vdf:payload> </content> </entry>
VDF is a proprietary format
. Basically, content items are encoded as a sequence of
vdf:field
elements - one for each field in the
content item. The fields in a content item are determined by its type
(as defined in the publication content-type
resource). In order to create a valid content item, therefore you need
to know its type: the name of the type, what fields it can contain and
what values are allowed in those fields.
VDF encompasses formats for both a payload document that contains actual data (as shown in the example above) and a model document that describes the structure of a payload document. A VDF model document, in other words, contains all the information you need to create a valid payload document of a particular type.
Given that you know the name of the publication you are creating a content item for and the name of its content type, you can retrieve the VDF model document that describes it as follows:
curl -u user:password -X GET http://host-ip-address/webservice/escenic/publication/pub-name/model/content-type/content-type-name
where:
- pub-name
-
is the name of the target publication
- content-type-name
-
is the name of the target content type
The model document contains the information you need to create a content
item of the specified type. For information about how different
Escenic
field types are described in a VDF model document, see
Process a Content Item. You must include the
URL of the model document in the model
attribute of
the root payload
element of the document you create
(as shown in the example above).
Save the document you have created in a file
(my-new-item.xml
, for example). In order to create
the new content item you can then POST
this file to
the URI of section you want to add it to. For example:
curl --include -u user:password -X POST -H "Content-Type: application/atom+xml" \>
http://host-ip-address/webservice/escenic/section/section-id/content-items --upload-file my-new-article.xmlHTTP/1.1 100 Continue Server: Resin/3.1.11 Content-Length: 0 Date: Wed, 11 Jan 2012 14:16:47 GMT HTTP/1.1 201 Created Server: Resin/3.1.11 Location: http://
host-ip-address/webservice/escenic/content/220771 Content-Type: application/octet-stream Content-Length: 0 Date: Wed, 11 Jan 2012 14:16:47 GMT
where section-id is the ID of the section to which the content item is to be added.
In order for the POST
operation to work, you must
specify a HTTP header as shown above.
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 addition and the server won't accept your new content item.
-
A response code in the 5xx range means there is a server error.
The Location
response specifies the location of the
newly-created content item: you can retrieve it by submitting a
GET
request to this URL.
A quick way of finding out how to create a correctly structured
content item in VDF format is to GET
a content item
of the same type and copy the structure.