Skip to end of metadata
Go to start of metadata

About

To add a comment to a blog is required send a comment Atom entry document that includes the Id of the blog posting that you are commenting on. Here's one easy way to do it with an asynchronous HTTP (Ajax) request using jQuery.

IBM Connections 4 documentation link: Creating comments

Atom API Request Details

Headers

Content-Type : application/atom+xml
TypePOST
URL

/blogs/{blog-id}/api/comments

Example:

https://www.mysite.com/blogs/46a251ac-08282c6fb555/api/comments

ResponseStatus Code: 201 Created

Example Atom Entry

<?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-4962762c-8a-4bfe563eedba"/>
  <content type='html'>
    I love to comment.
  </content>
</entry>

Note

Each blog entry has a unique Id, In line 5: <thr:in-reply-to ref="urn:lsid:ibm.com:blogs:entry-4962762c-8a-4bfe563eedba"/> is necessary to include that Id.

Example using jQuery

var strData = '<?xml version="1.0" encoding="UTF-8"?>';
    strData += '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0">';
    strData += '<id>ignored</id><title type="text">ignored</title>';
    strData += '<thr:in-reply-to ref="urn:lsid:ibm.com:blogs:entry-4962762c-8a-4bfe563eedba"/>';
    strData += '<content type="html">I love to comment.</content></entry>';

$.ajax({
    url : "https://www.mysite.com/blogs/46a251ac-08282c6fb555/api/comments",
    type : "POST",
	contentType: "application/atom+xml",
    async : true,
	data: strData,
    statusCode : {
        201 : function() {
            console.log('comment created');
        }
    },
    error: function(jqXHR, textStatus, errorThrown) {
        console.log(jqXHR + " - " + textStatus + ' - ' + errorThrown);
    }
});

Note:  console.log can throw errors in IE, they are there for illustrative purposes only and should be changed as required.

About the author

Enterprise Web Developer
Joaquin is an Enterprise Web Developer at Base22 with over seven years of experience designing and developing web solutions for enterprise clients. He is a well rounded web developer with skills building interfaces in IBM WebSphere Portal and WCM, IBM Connections, and many others. He is an Oracle Certified Java Developer and a Microsoft Certified Visual Studio Developer. He blogs at http://j-arellano.com