An easy way to use the Chatter REST API
When the Chatter REST API team started work, they discovered there was to do than originally anticipated. So, they created a Java wrapper that could be easily reused by anyone working with Java and the Chatter REST API.
A while ago we set out to make our Content Management System social. We wanted it to talk to us, inform us of information we found useful. We decided to hook up our publishing system to Chatter. Whenever a page you were interested in changed, you would get a notification immediately in your Chatter Feed.
But when we starting working on the Chatter REST API internally, it was hard. Documentation wasn’t easy to find, examples didn’t work for us and functionality didn’t match with the text. To be fair, it was still in development, but we needed it now.
So, instead of letting it go, we wrote our own library – or wrapper if you prefer – in Java around the REST API. We wrote in such a way that it could be easily reused by whoever uses Java and the Chatter REST API.
We made it as easy and versatile as possible, and the end result is so easy anybody can use it. Below is an example of how you would create a connection to your Salesforce.com org and post something to your team’s Chatter wall.
ChatterService service = new ChatterService(new ChatterData());
Message msg = new Message();
msg.addSegment(new TextSegment("Hey "));
msg.addSegment(new TextSegment(", check out this website: "));
msg.addSegment(new TextSegment(" #salesforce"));
ChatterCommand cmd = new PostToThreadCommand(TEAM_GROUP_ID);
Easy as that! ChatterData holds the credential data, the ChatterService acts as the portal to your org, and you pass it ChatterCommands (defining where the message should go) and Messages.
In the case of our Content Management System, it looks something like this:
This wrapper has recently reached open source status and it is hosted on Github. You can find the library here: https://github.com/forcedotcom/JavaChatterRESTApi.