Sie sind auf Seite 1von 2

Chatter REST API

Cheat Sheet

Collaboration
Overview

Add Comments

The Chatter REST API provides access to Chatter feeds and social data such as users,
groups, and followers, via a standard JSON/XML-based API.

To add a comment to a feed item, use the comments resource with POST and the request
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:
https://na1-salesforce.com
And the version information is this:
/services/data/v22.0/chatter
And youre using the following resource:
/feeds/news/me/feed-items
Put together, the full URL to the resource is:
https://na1-salesforce.com/services/data/v22.0/chatter/feeds/news/
me/feed-items

/feed-items/0D5D0000000DaSbKAK/comments?text=New+post

Follow Records
Use the users resource to follow a specific record. A record can be any object in
Salesforce, such as a custom record, a file, a user, and so on.
To follow a record, use POST with the subjectId request parameter. This example follows
a user:

Authentication

/users/me/following?subjectId=005D0000001GpHp

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

Unfollow Records

Resources
The following resources are available:
Resource

Description

/comments

The specified comment.

/feed-items

The specified feed item.

/feeds/news

The Chatter news feed of either the current user or a


specified user.

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:
/users/me | userID/following
To unfollow a record, use DELETE. For example:
/subscriptions/0E8D00000001JkFKAU

Feeds Resources
Chatter API resources represent many feed types, such as news feeds, user-profile feeds,
group feeds, and so on.
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
of the feed items for that feed. For example:

/feeds/record

The feed for a record, such as a user, custom object, or


group.

/feeds/to

The feed of @ mentions of either the current user or a


specified user, as well as posts to that users feed.

/feeds/files/me
/feeds/groups/me
/feeds/user-profile/005D0000001GLowIAN

/feeds/user-profile

The user-profile feed of either the current user or a specified


user.

All feeds have a feed-items resource that returns the feed items for that feed. For
example, to return the feed items for the current users news feed, use GET and the
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

/likes

The specified like.

/subscriptions

The specified subscription, which is what the user is


following.

/users

Either the current user or a specified users Chatter profile


details, such as the description they have in their About Me
section. This is not a feed. To access the user-profile feed,
use the /feeds/user-profile resource.

Chatter API has the following resources for working with groups:
/groups returns information about the specified group, such as members in the group,
the group photo, and so on
/group-memberships returns information about the specified member of a group
To get a list of all the groups the current signed-in user is a member of, use GET with the
following resource:
/groups

Like a Feed Item

To add a member to a specific group, use the groups resource and POST with the group
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
must also specify the feed item that you are adding the like to.

/groups/0F9D000000006bOKAQ/members?memberId=005D0000001GLowIAB

The following example adds a like to an existing feed item, which has an ID of
0D5D0000000DaZBKA0.
/feed-items/0D5D0000000DaZBKA0/likes

To post to a specific group, use the /feeds/record resource and POST with the group
ID, and the text request parameter. For example:
/feeds/record/0F9D000000006bO/feed-items
?text=Has+everyone+seen+the+latest+building+proposal?

http://sfdcgurukul.blogspot.com

Message Segments

Pagination

Message segments are returned as part of the body of a feed item. Each message segment
contains the formatted text of the feed item, as well as information about the type of feed
item.

Feeds, lists of groups or records a user is following, and other resources may return more
items than can be contained in a single page. The return for all of these collections contains
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
example:
<xml parsing psuedo code>
StringBuilder feedItemText = new StringBuilder();
NodeList nodes = feedItemElement.getElementsByTagName("body").
item(0).firstChild().getChildNodes();
for(int i=0; i<nodes.getLength(); i++) {
Node nextNode = nodes.item(0);
if(!nextNode instanceof Element) {
continue;
}

Element segmentElement = (Element)nextNode;


String text = segmentElement.
getElementsByTagName("text").item(0).getTextContent();
feedItemText.append(text);

someWriter.write(feedItemText);
</xml parsing psuedo code>

The following is an example return from a news feed:


{

"currentPageUrl": "/services/data/v22.0/chatter/feeds/
news/005x0000001j2OwAAI/feed-items",
. . .
"nextPageUrl": "/services/data/v22.0/chatter/feeds/
news/005x0000001j2OwAAI/feed-items?page=2011-07-01T14%3A11%3A54Z%2
C0D5x0000001NUGICA4"
}
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.

Update User Status


You can update a users 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.)
The following example updates a users status using the news resource:
/feeds/news/me/feed-items?text=New+post
The following example updates a users status using the record resource:
/feeds/record/005D0000001GLowIAN/feed-items?text=New+post

http://sfdcgurukul.blogspot.com

Das könnte Ihnen auch gefallen