Testing the Chatter API

February 13, 2014 Appirio

By Mitul Patel

chatter apiThere has always been interest to integrate with Chatter. Chatter’s business value potentially increases several fold by integrating with other enterprise applications. The Chatter API does a great job of exposing interfaces for integration.

As with any development, testing Chatter integration is an important task. The Chatter API, being a REST based API, can be tested using several different tools. One great tool is REST Explorer which can be found in workbench. It is web based and has a very intuitive UI. The feature to show raw responses is my personal favorite. If the setup is done correctly, it doesn’t require you to specify authentication (like OAuth token).

Resource URI

The Chatter API’s resource URI consists of a salesforce server URL, version information and the resource. For example, if the server instance is ‘https://na1.salesforce.com’,  the version information is ‘/services/data/v29.0’ and the resource is ‘/chatter/feeds/news/me/feed-items’, the full URI is: ‘https://na1.salesforce.com/services/data/v29.0/chatter/feeds/news/me/feed-items’.

In workbench a server instance need not be specified. For the above example, to access the resource in workbench you only need to specify – ‘/services/data/v29.0/chatter/feeds/news/me/feed-items’.

The following diagram depicts a typical Chatter feed. A feed has different feed-items, which may have comments. Feed-items can be organized in topics.

Chatter Feed

A feed is made up of different feed-items. There are multiple types of feeds in Chatter – news feed, record feed and user profile feeds etc. The resource for feeds is – /services/data/v29.0/chatter/feeds

Feed Items

A feed item is an entry in the feed. Chatter feed-items for any record (Account, Opportunity etc.) can be accessed from the resource – /services/data/v29.0/chatter/feeds/record/record-id/feed-items. Each individual feed item has its own resource – /chatter/feed-items/feedItemId

To add another feed-item to a feed, post the body to the feed-items resource. For example, passing the “Message Body” input (see below)  in the request body to post to /services/data/v29.0/chatter/feeds/record/record-id/feed-items will add another feed-item to resource. This feed-item will have a link , in this case www.appirio.com. Check out the Chatter REST API Developers Guide for more information on input.

{

“body” : {

  “messageSegments” : [ {

    “type” : “Text”,

    “text” : “An interesting post from Chatter API”

  } ]

},

“attachment”:

  {

  “attachmentType”:”Link”,

  “url”: “http://www.appiriio.com”,

  “urlName”: “GPXPress News Feed”

  }

}

Comment

A feed item can also have comments associated with it. The resource for comments for a specific feed-item is – /chatter/feed-items/feedItemId/comments. An individual comment can be accessed from the resource – /chatter/comments/commentId

To add comments to a feed-item, just post the “Message body” to the comments resource. The following is an example of input in JSON format.

{

 “body”:{

  “messageSegments” : [

    {

       “type” : “Text”,

       “text” : “Another comment”

    }

  ]

  }

}

Topic

Feed items can be organized in topics as well. A list of all topics can be found at the resource – /connect/topics. A specific topic has the resource – /connect/topics/topicId and the feed for the topic is at – /services/data/v29.0/chatter/feeds/topics/topicId/feed-items

APIs are provided to search topic. The resource to search for an exact topic is – /services/data/v29.0/connect/topics?q=searchTerm&exactMatch=true

Mention

A mention is the “@“ character followed by a user or group name. When a user or group is mentioned in a feed-item or comment, they receive a notification.

The type of  “mention” can be specified for input message segment. Following is an example  –

{ “body” :

  {

  “messageSegments” : [

     {

        “type”: “mention”,

        “id”:”005i0000000yiEt”

      },

      {

         “type”: “text”,

         “text”:”A comment with mention”

       }

  ]

  }

}

Note: Default request/response for a resource is in JSON format. If “xml” request/response is desired, the extension “.xml” should be added to the end of resource.

References

1. Chatter REST API Developers Guide 

App Development Best Practices Whitepaper

Previous Article
Two New Google Calendar Features to Make Meetings Easier
Two New Google Calendar Features to Make Meetings Easier

By Anne Frances Durfee New features in Google Calendar make it easier for you to organize meetings with you...

Next Article
Getting Off The "Happy Path": A Cool Approach To Synthetic Data.
Getting Off The "Happy Path": A Cool Approach To Synthetic Data.

By Kyle Bowerman (@kylebowerman) As developers, most of us first code our solution to data that we know wil...