Creating blog posts
Added by IBM contributorIBM | Edited by IBM contributorPaul Bastide on December 21, 2015
Rate this article 1 starsRate this article 2 starsRate this article 3 starsRate this article 4 starsRate this article 5 stars

To create a blog post, send an Atom entry document containing the new blog post entry to the user's weblog Entries resource.
 
1. Create an Atom document to define the post that you want to add to the blog. For example:
2. Retrieve the Blogs service document using the following request:
3. 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.
4. 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:
5. 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.
Input
Method URI Description
POST /blogs/{handle}/api/entries Value of the href attribute of <collection title="weblog Entries"> element in User's Service Document
Content Type: application/atom+xml
Sample Request:
<?xml version="1.0" encoding="UTF-8"?>

<entry 

 xmlns="http://www.w3.org/2005/Atom" 

 xmlns:app="http://www.w3.org/2007/app" 

 xmlns:snx="http://www.ibm.com/xmlns/prod/sn">
   
    <title type="text">Entry to Blog test</title>

    <summary type="html">
    Test Entry - BLOG</summary>
    <content type="html">
    Test Entry - BLOG </content>

    </entry>

Name Type Optional Description
handle
string No {handle} represents the blog handle. A handle is specified when a blog is first created and is used in the construction of web addresses used to query the entries in a blog
The handle can be the Community Uuid.
Name Type Optional Description
X-LConn-RunAs
string Yes The value should be in such format: userid=<user ext id>,username=<user name>,useremail=<user mail> .
This header enables impersonation and must works with Blogs admin user to authenticate request. If the user does not exists, an inactive user will be created with specified userid , username and usermail. If the user exists, username and useremail can be omitted.
eg:userid=BFB5FDCB-B0E2-408A-A351-09103D8D5527,username=xxxxxx,useremail=xxxx@cn.ibm.com
Output
Content Type: application/atom+xml
Name Type Optional Description
Location
string No Link to edit_url of the new blog post. You can use the web address specified here to subsequently update the blog post.
Code Description
201
Indicates that the blog post was successfully created. If an error occurs, this header contains one of the error codes.
400
Bad Request.
401
Unauthorized.
Examples
1. Create an Atom document to define the post that you want to add to the blog. 2. Retrieve the Blogs service document using the following request 3. 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. 4. 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: 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.
<?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>

GET /blogs/api HTTP/1.1

	Host: blogs.enterprise.example.com


...

	<workspace>

	<atom:title xmlns:atom="http://www.w3.org/2005/Atom">

	ajones

	</atom:title>

	<collection

	href="https://blogs.enterprise.example.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.example.com:9444/blogs/ajones/api/tags">

	</categories>

	</collection>

	...

	</workspace>

	...

POST /blogs/ajones/api/entries HTTP/1.1

	Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

	Host: blogs.enterprise.example.com:9444

	Accept: */*

	Content-Type: application/atom+xml

	Content-Length: 747



For 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.example.com:9444/

	blogs/ajones/api/entries" -d @newblogpost.xml -u ajones@example.com:jones -k


Response returned by the server
<?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.example.com:9444/blogs/ajones/entry/

	project_x">

	</link>

	<link

	href="https://blogs.enterprise.example.com:9444/blogs/ajones/api/entries/

	535477e8-8fd6-4ec7-902c-1216c2318b57"

	rel="edit"

	type="application/atom+xml">

	</link>

	<link

	href="https://blogs.enterprise.example.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.example.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.example.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@example.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>

	]]&gt;

	</content>

	</entry>