Introduction to the Chatter REST API

The Chatter REST API provides access to Chatter functionality, including feeds, users, groups, followers, and files. Being a REST API, it can be integrated in Web, mobile, and desktop applications built in any technology that is capable of making HTTP requests. It is a valuable alternative to using the Chatter data model directly, hiding the details of how Chatter data is represented and offering a high-level API instead.


Note

For more information about the Chatter REST API, consult the Chatter REST API Developer’s Guide, found at http://www.salesforce.com/us/developer/docs/chatterapi/index.htm.


To get started with Chatter REST API, examine some examples of REST requests for common Chatter functionality. Like other REST examples in the book, the following three listings can be run from the command line. They assume you have an authorization token set in the TOKEN environment variable, and that you replace the instance na15 with your own Salesforce instance.

Listing 12.15 requests the News Feed of the current user, which is the Chatter feed found on the Home tab. To request a different user’s News Feed, replace me with the user record’s unique identifier.

Listing 12.15 Sample Request for News Feed


curl https://na15.salesforce.com/services/data/v28.0
/chatter/feeds/news/me/feed-items
 -H "Authorization: OAuth "$TOKEN -H "X-PrettyPrint:1"


Listing 12.16 returns a list of all of the records followed by the current user.

Listing 12.16 Sample Request for Followed Records


curl https://na15.salesforce.com/services/data/v28.0
/chatter/users/me/following
 -H "Authorization: OAuth "$TOKEN -H "X-PrettyPrint:1"


To create a simple text-type feed post, follow the sample found in Listing 12.17.

Listing 12.17 Sample Request for Posting a Feed Item


echo '{ "body" : { "messageSegments" :
 [ { "type": "Text", "text" : "Hello world" } ] } }' |
  curl -X POST -H 'Content-type: application/json'
  -H "Authorization: OAuth "$TOKEN -H "X-PrettyPrint:1" -d @-
  https://na15.salesforce.com/services/data/v28.0
/chatter/feeds/news/me/feed-items



Tip

To adapt the command in Listing 12.17 and other listings in this chapter to run in Windows Command Prompt, remove the single quotation mark characters (') in the echo statement, replace the single quotation mark characters around the Content-type header with double quotation mark characters ("), remove the backslash () line-continuation characters and concatenate the lines into a single line, and replace $TOKEN with _KEN%.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.146.134