1. Chatter REST API
Collaboration
Cheat Sheet
Overview Add Comments
The Chatter REST API provides access to Chatter feeds and social data such as users, To add a comment to a feed item, use the comments resource with POST and the request
groups, and followers, via a standard JSON/XML-based API. parameter text. As part of the comments resource, you must also specify the feed item
that you are adding the comment to.
Constructing the URL The following example adds a comment to an existing feed-item, which has an ID of
0D5D0000000DaSbKAK:
All Chatter API resources are accessed using a base URI for your company, version
information, and the named resource. For example, if the base URI is this: /feed-items/0D5D0000000DaSbKAK/comments?text=New+post
https://na1-salesforce.com
And the version information is this:
/services/data/v22.0/chatter Follow Records
And you’re using the following resource:
/feeds/news/me/feed-items Use the users resource to follow a specific record. A record can be any object in
Put together, the full URL to the resource is: Salesforce, such as a custom record, a file, a user, and so on.
https://na1-salesforce.com/services/data/v22.0/chatter/feeds/news/
me/feed-items To follow a record, use POST with the subjectId request parameter. This example follows
a user:
/users/me/following?subjectId=005D0000001GpHp
Authentication
Chatter API uses OAuth 2.0 for authentication. The return from a successful authentication
includes an access token, which can be used for subsequent calls to the Chatter API Unfollow Records
resources.
Use the subscriptions resource to unfollow a record. You must use the subscription ID
with the subscriptions resource. To get subscription IDs, use the following resource:
Resources /users/me | userID/following
The following resources are available:
To unfollow a record, use DELETE. For example:
Resource Description
/subscriptions/0E8D00000001JkFKAU
/comments The specified comment.
Feeds Resources
/feed-items The specified feed item.
Chatter API resources represent many feed types, such as news feeds, user-profile feeds,
group feeds, and so on.
/feeds/news The Chatter news feed of either the current user or a
specified user. Most feeds can be accessed with either the keyword me or a specified user ID, such as
005D0000001GLowIAN. In addition, all feeds have a top-level resource that returns a URL
/feeds/record The feed for a record, such as a user, custom object, or of the feed items for that feed. For example:
group.
/feeds/files/me
/feeds/to The feed of @ mentions of either the current user or a /feeds/groups/me
specified user, as well as posts to that user’s feed. /feeds/user-profile/005D0000001GLowIAN
All feeds have a feed-items resource that returns the feed items for that feed. For
/feeds/user-profile The user-profile feed of either the current user or a specified example, to return the feed items for the current user’s news feed, use GET and the
user. following resource:
/group-memberships The specified group membership. /feeds/news/me/feed-items
/groups The specified group. This is not a feed. To get the feed for a
group, use the record resource. Groups
Chatter API has the following resources for working with groups:
/likes The specified like.
/groups — returns information about the specified group, such as members in the group,
the group photo, and so on
/subscriptions The specified subscription, which is what the user is
following. /group-memberships — returns information about the specified member of a group
/users Either the current user or a specified user’s Chatter profile To get a list of all the groups the current signed-in user is a member of, use GET with the
details, such as the description they have in their “About Me” following resource:
section. This is not a feed. To access the user-profile feed,
use the /feeds/user-profile resource. /groups
To add a member to a specific group, use the groups resource and POST with the group
Like a Feed Item ID, the memberID request parameter, and the specified user ID. For example:
To like a feed item, use the likes resource with POST. As part of the likes resource, you /groups/0F9D000000006bOKAQ/members?memberId=005D0000001GLowIAB
must also specify the feed item that you are adding the like to.
To post to a specific group, use the /feeds/record resource and POST with the group
The following example adds a like to an existing feed item, which has an ID of ID, and the text request parameter. For example:
0D5D0000000DaZBKA0.
/feeds/record/0F9D000000006bO/feed-items
/feed-items/0D5D0000000DaZBKA0/likes ?text=Has+everyone+seen+the+latest+building+proposal?
http://developer.force.com
2. Message Segments Pagination
Message segments are returned as part of the body of a feed item. Each message segment Feeds, lists of groups or records a user is following, and other resources may return more
contains the formatted text of the feed item, as well as information about the type of feed items than can be contained in a single page. The return for all of these collections contains
item. both a currentPageUrl and a nextPageUrl property. The currentPageUrl contains
a URL that points to the current page of items, while the nextPageUrl contains the URL
for the next page of items.
Any feed item can be composed by rendering the list of message segments in the given
order. Rendering a message segment is as easy as displaying the text property. For The following is an example return from a news feed:
example:
{
<xml parsing psuedo code> "currentPageUrl": "/services/data/v22.0/chatter/feeds/
StringBuilder feedItemText = new StringBuilder(); news/005x0000001j2OwAAI/feed-items",
NodeList nodes = feedItemElement.getElementsByTagName("body"). . . .
"nextPageUrl": "/services/data/v22.0/chatter/feeds/
item(0).firstChild().getChildNodes();
news/005x0000001j2OwAAI/feed-items?page=2011-07-01T14%3A11%3A54Z%2
for(int i=0; i<nodes.getLength(); i++) { C0D5x0000001NUGICA4"
Node nextNode = nodes.item(0); }
if(!nextNode instanceof Element) {
continue; The second page of items contains a new value for nextPageUrl. To page through the
} feed items, use the URL from each subsequent page. There are no more pages when
nextPageUrl is null.
Element segmentElement = (Element)nextNode;
String text = segmentElement.
getElementsByTagName("text").item(0).getTextContent(); Update User Status
feedItemText.append(text); You can update a user’s status using the news, to, or record feed resources, with POST
} and the request parameter text. (When using the record or to resources, the specified
ID must be a user ID and the same as the current, signed-in user.)
someWriter.write(feedItemText);
The following example updates a user’s status using the news resource:
</xml parsing psuedo code>
/feeds/news/me/feed-items?text=New+post
The following example updates a user’s status using the record resource:
/feeds/record/005D0000001GLowIAN/feed-items?text=New+post
For other cheatsheets:
http://developer.force.com/cheatsheets 082011