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.

Table 1. 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.

Note: 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

Location: url

Errors

For example, to create a blog post, perform the following steps:

  1. 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>

  2. Retrieve the Blogs service document using the following request:

      GET /blogs/api HTTP/1.1
      Host: blogs.enterprise.example.com

  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.

      ...
      <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>
      ...

  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:

      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 header:

      HTTP/1.1 201 Created
      Content-Type: application/atom+xml; type=entry
      Content-Location: https://blogs.enterprise.example.com:9444/blogs/ajones/api/
       entries/535477e8-8fd6-4ec7-902c-1216c2318b57
      Location: https://blogs.enterprise.example.com:9444/blogs/ajones/api/entries/
       535477e8-8fd6-4ec7-902c-1216c2318b57
      Last-Modified: Mon, 17 Nov 2008 20:52:26 GMT
      Content-Language: en-US

      Response 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.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>

  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.


Parent topic

Work with blog posts

Related reference
Blog posting content


   

 

});