Create comments 

To add a comment to a blog posting, send a comment Atom entry document to the web address specified in the href attribute of the Comments <collection> element of the blog as specified in the service document or send the comment Atom entry document directly to the comments feed. Include the ID of the blog posting that you are commenting on in the comment Atom entry.

You can use the API to create and retrieve comments. However, after comments are created, they cannot be modified. Only the blog owner can delete comments.

See Authenticating requests for information about how to authenticate the request.

To create a blog comment...

  1. Retrieve the Blogs service document. See Retrieve the Blogs service document.

  2. In the service document, locate the workspace for the blog, locate the Comment Entries Atom collection within the workspace, and then copy the web address in the href attribute of the Comments collection.

  3. Determine the ID of the entry that you want to add the comment as a response to by getting a feed of the entries in the blog. You can do so by sending a GET request to the web address in the href attribute of the Weblog Entries collection. From the returned feed, find the blog of interest and the entry to which you want to add a comment. Copy the value of the <id> element for that entry.

  4. Send a POST request to the web address that you noted in the previous step. Pass a comment Atom entry document as input on the request. In the Atom document, define the entry that you want to add the comment to and the content of the comment itself.

Table 1. Atom API request details

Method Resource URI Input representation
POST Comments Value of the href attribute of the <collection> element with a child <title> element having a value of Comments in each blog workspace in the service document. comment
POST Comments /services/atom/{handle}/comments

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

Note: This resource was introduced in the 1.x version of the Blogs API. It is provided here for backwards compatibility.

comment

Input

Provide a comment Atom entry document.

Note: The content type of the Atom entry document must be application/atom+xml.

Note: If you are using the URL from the publishing API service document or the /services/atom/{handle}/comments resource to create a comment, provide the entry ID specified in the <thr:in-reply-to> element to indicate which entry the comment is for.


Output

An Atom entry document containing the new blog comment.

Returned HTTP headers

HTTP/1.1 201 Created

Location: url

Error codes


Example

Request:

> POST /blogs/myblog/api/comments HTTP/1.1
> Authorization: Basic xxx
> Host: enterprise.example.com
> Accept: */*
> Content-Type: application/atom+xml
> Content-Length: 353

Comment Atom entry document provided as input to the request:

<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:thr="http://purl.org/syndication/thread/1.0">
  <id>ignored</id>
  <title type='text'>ignored</title>
  <thr:in-reply-to ref="urn:lsid:ibm.com:blogs:entry-49d22e3e-4f0f-4499-b979-d64dc23ad21d"/>
  <content type='html'>
    I love to comment on topics.
  </content>
</entry>

Response:

< HTTP/1.1 201 Created
< Date: Tue, 03 Aug 2010 19:24:42 GMT
< Server: IBM_HTTP_Server
< X-LConn-Auth: false
< X-UA-Compatible: IE=EmulateIE7
< Expires: Thu, 1 Jan 1970 00:00:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate
< Location: https://enterprise.example.com:443/blogs/myblog/api/comments/
c2d87716-e965-4077-9a0b-f679f6d83d3a
< Content-Location: https://enterprise.example.com:443/blogs/myblog/api/c
omments/c2d87716-e965-4077-9a0b-f679f6d83d3a
< Last-Modified: Tue, 03 Aug 2010 19:24:44 GMT
< Set-Cookie: ...
< Set-Cookie: ...
< Set-Cookie: JSESSIONID=...
< Transfer-Encoding: chunked
< Content-Type: application/atom+xml; type=entry
< Content-Language: en-US
<
<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom">
  <id>urn:lsid:ibm.com:blogs:comment-c2d87716-e965-4077-9a0b-f679f6d83d3a</id>
  <link 
   href="https://enterprise.example.com:443/blogs/myblog/api/c2d87716-e965-4077-9a0b-f679f6d83d3a" 
   rel="edit" 
   type="application/atom+xml">
  </link>
  <link 
   href="https://enterprise.example.com/blogs/myblog/entry/just_below#comments-1280863484351" 
   rel="alternate" 
   type="text/html">
  </link>
  <link 
   href="http://enterprise.example.com/blogs/issuecategories" 
   rel="http://www.ibm.com/xmlns/prod/sn/issues">
  </link>
  <link 
   href="http://enterprise.example.com/blogs/home/api/reports/comments/c2d87716-e965-4077-9a0b-f679f6d83d3a" 
   rel="http://www.ibm.com/xmlns/prod/sn/reports" 
   type="application/atom+xml">
  </link>
  <app:collection 
   href="https://enterprise.example.com:443/blogs/myblog/api/recommend/comments/c2d87716-e965-4077-9a0b-f679f6d83d3a" 
   xmlns:app="http://www.w3.org/2007/app">
    <atom:title xmlns:atom="http://www.w3.org/2005/Atom">
     Recommendations
    </atom:title>
    <atom:category term="recommend" scheme="http://www.ibm.com/xmlns/prod/sn/collection" xmlns:atom="http://www.w3.org/2005/Atom">
    </atom:category>
    <app:categories fixed="yes"></app:categories>
  </app:collection>
  <snx:moderation status="approved" xmlns:snx="http://www.ibm.com/xmlns/prod/sn"></snx:moderation>
  <title type="text">Re: just below</title>
  <updated>2010-08-03T19:24:44.351Z</updated>
  <app:edited xmlns:app="http://www.w3.org/2007/app">2010-08-03T19:24:44.351Z</app:edited>
  <published>2010-08-03T19:24:44.351Z</published>
  <author>
    <name>Jim Smith</name>
    <email>jsmith@example.com</email>
    <snx:userid xmlns:snx="http://www.ibm.com/xmlns/prod/sn">4fda6cc0-0101-102e-88dd-f78755f7e0ed</snx:userid>
    <snx:userState xmlns:snx="http://www.ibm.com/xmlns/prod/sn">active</snx:userState>
  </author>
  <content type="html">    I love tocomment on topics.  </content>
  <thr:in-reply-to 
   ref="urn:lsid:ibm.com:blogs:entry-49d22e3e-4f0f-4499-b979-d64dc23ad21d" 
   href="https://enterprise.example.com/blogs/myblog/entry/just_below" 
   type="text/html" 
   xmlns:thr="http://purl.org/syndication/thread/1.0">
  </thr:in-reply-to>
  <snx:trackbacktitle xmlns:snx="http://www.ibm.com/xmlns/prod/sn">Jim Smith</snx:trackbacktitle>
  <snx:rank scheme="http://www.ibm.com/xmlns/prod/sn/recommendations" xmlns:snx="http://www.ibm.com/xmlns/prod/sn">0</snx:rank>
  <app:control xmlns:app="http://www.w3.org/2007/app">
    <app:draft>no</app:draft>
    <snx:approved xmlns:snx="http://www.ibm.com/xmlns/prod/sn">yes</snx:approved>
  </app:control>
</entry>
* Connection #0 to host enterprise.example.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):


Parent topic

Commenting on blog posts

Related reference
Blogs comment content
Navigate Blogs subscription API resources
Navigate Blogs publishing API resources


   

 

});