Home
Create blog posts
To create a blog post, send an Atom entry document containing the new blog post entry to the user's Weblog Entries resource.
See Authenticating requests for information about how to authenticate the request.
Atom API request details
Method Resource URI Input representation POST Weblog Entries Value of the href attribute of <collection title="Weblog Entries"> element in User's Service Document blog post
Input
Provide a blog post Atom entry document.The content type of the Atom entry document must be application/atom+xml.
Output
An Atom entry document containing the new blog post. Returned HTTP Headers
- HTTP/1.1 201 Created
- Indicates that the blog post was successfully created. If an error occurs, this header will contain one of the error codes below.
- Location: url
- Link to edit_url of the new blog post. You can use the Web address specified here to subsequently update the blog post.
Errors
- HTTP/1.1 400 Bad Request
- HTTP/1.1 401 Unauthorized
For example, to create a blog post, perform the following steps:
- Create an Atom document to define the post that you want to add to the blog. For example:
?xml version="1.0" encoding="utf-8"?> <!-- Input for new Blog entry posting --> <entry xmlns="http://www.w3.org/2005/Atom"> <title type="text">Project Gemini</title> <category term="partner" /> <category term="demo" /> <content type="html"> <![CDATA[ Theme controls the look and layout of your blog.<br> ]]> </content> </entry>
- Retrieve the Blogs service document using the following request:
GET /blogs/api HTTP/1.1 Host: blogs.enterprise.acme.com
- In the service document, find the workspace for the blog in which you want to create a new post, and then retrieve the Web address of the "Weblog Entries" collection in that workspace.
... <workspace> <atom:title xmlns:atom="http://www.w3.org/2005/Atom"> ajones </atom:title> <collection href="https://blogs.enterprise.acme.com:9444/blogs/ajones/api/entries"> <atom:title xmlns:atom="http://www.w3.org/2005/Atom">Weblog Entries</atom:title> <id xmlns="http://www.w3.org/2005/Atom"> urn:lsid:ibm.com:blogs:entries-a8e30743-199b-486e-acc3-0f9f836775a1 </id> <accept>application/atom+xml;type=entry</accept> <categories fixed="no" href="https://blogs.enterprise.acme.com:9444/blogs/ajones/api/tags"> </categories> </collection> ... </workspace> ...
- Send the blog post Atom document to the Web address you retrieved in the previous step. Do so using an HTTP POST request that is defined as follows:
POST /blogs/ajones/api/entries HTTP/1.1 Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Host: blogs.enterprise.acme.com:9444 Accept: */* Content-Type: application/atom+xml Content-Length: 747For example, if you are using cURL, you could specify the following command to make the request:
curl -s -o newblogpostout.xml -v -X POST -H "Content-Type: application/atom+xml" "https://blogs.enterprise.acme.com:9444/ blogs/ajones/api/entries" -d @newblogpost.xml -u ajones@acme.com:jones -kResponse header:
HTTP/1.1 201 Created Content-Type: application/atom+xml; type=entry Content-Location: https://blogs.enterprise.acme.com:9444/blogs/ajones/api/ entries/535477e8-8fd6-4ec7-902c-1216c2318b57 Location: https://blogs.enterprise.acme.com:9444/blogs/ajones/api/entries/ 535477e8-8fd6-4ec7-902c-1216c2318b57 Last-Modified: Mon, 17 Nov 2008 20:52:26 GMT Content-Language: en-USResponse content:
<?xml version="1.0"?> <entry xml:lang="en-US" dir="ltr" xmlns="http://www.w3.org/2005/Atom"> <id>urn:lsid:ibm.com:blogs:entry-535477e8-8fd6-4ec7-902c-1216c2318b57</id> <link href="https://blogs.enterprise.acme.com:9444/blogs/ajones/entry/ project_x"> </link> <link href="https://blogs.enterprise.acme.com:9444/blogs/ajones/api/entries/ 535477e8-8fd6-4ec7-902c-1216c2318b57" rel="edit" type="application/atom+xml"> </link> <link href="https://blogs.enterprise.acme.com:9444/blogs/ajones/api/entrycomments/ 535477e8-8fd6-4ec7-902c-1216c2318b57" rel="replies" type="application/atom+xml" thr:count="0" xmlns:thr="http://purl.org/syndication/thread/1.0"> </link> <link href="https://blogs.enterprise.acme.com:9444/blogs/BVThome1008162116/api/ reports/535477e8-8fd6-4ec7-902c-1216c2318b57" rel="http://www.ibm.com/xmlns/prod/sn/reports" type="application/atom+xml"> </link> <collection href="https://blogs.enterprise.acme.com:9444/blogs/ajones/api/entrycomments/ 535477e8-8fd6-4ec7-902c-1216c2318b57" xmlns="http://www.w3.org/2007/app"> <atom:title xmlns:atom="http://www.w3.org/2005/Atom">Comments</atom:title> <accept>application/atom+xml;type=entry</accept> <categories fixed="yes"> </categories> </collection> <title type="text">Project X</title> <updated>2008-11-17T20:52:26.000Z</updated> <app:edited xmlns:app="http://www.w3.org/2007/app"> 2008-11-17T20:52:26.000Z </app:edited> <published>2008-11-17T20:52:26.000Z</published> <snx:rank scheme="http://www.ibm.com/xmlns/prod/sn/recommendations" xmlns:snx="http://www.ibm.com/xmlns/prod/sn"> 0 </snx:rank> <snx:rank scheme="http://www.ibm.com/xmlns/prod/sn/comment" xmlns:snx="http://www.ibm.com/xmlns/prod/sn"> 0 </snx:rank> <snx:rank scheme="http://www.ibm.com/xmlns/prod/sn/hit" xmlns:snx="http://www.ibm.com/xmlns/prod/sn"> 0 </snx:rank> <author> <name>Amy Jones</name> <email>ajones@acme.com</email> </author> <category term="partner"> </category> <category term="demo"> </category> <app:control xmlns:app="http://www.w3.org/2007/app"> <app:draft>no</app:draft> <snx:comments enabled="yes" days="7" xmlns:snx="http://www.ibm.com/xmlns/prod/sn"> </snx:comments> </app:control> <content type="html"> <![CDATA[ Theme controls the look and layout of your blog.<br> ]]> </content> </entry>
- You can use the Web address in the <link rel="edit" type="application/atom+xml" ... > element in the response to subsequently update the blog post using the HTTP PUT command.
Related reference