As part of my blog series I describe below some tips and tricks for how to use the Connections REST APIs from XPages.
I strongly suggest to use the XPages Social Enabler infrastructure which is included in the Extension Library project on OpenNTF. I documented most of the functionality in chapter 13 of the new XPages book.
The Connections wiki contains documentation about the REST APIs. The getting started gives some samples for typical API calls, e.g. to get a list of the communities of the current user: http://sbf3012.boeblingen.de.ibm.com:81/communities/service/atom/communities/my.
One thing I had to learn was that the documentation mostly doesn’t define the URLs of the REST APIs. Instead it only says that the URLs should be read via another URL request for the applications’ service documents, e.g. to find out the URL to get the user’s status.
In some cases absolute URLs are defined in the wiki. For example the documentation to find specific user profiles defines the URL “/atom/profile.do”. It took me some time though to figure out that I actually had to use “/profiles/atom/profile.do” to get the profile feed.
Here is a simple sample for how to read the name of a user given the user’s id. In the NSF’s xsp.properties file I define to use the connectionsLtpa bean when the name ‘connections’ is used.
In faces-config.xml I define the managed bean:
In the Java code you can then use ConnectionsService and the method get, post, put and delete to invoke the REST APIs. There is a convenience API sbt.XmlNavigator to easily parse the Atom/XML output.
In my Lotusphere session I used another sample which posted information to Connections:
Note that on slide 33 you should actually use EndpointFactory.getEndPoint to get the endpoint rather than JSFUtil.getVariable. JSFUtil returns a specific managed bean while the EndpointFactory returns the right managed bean for Connections dependent on your settings in xsp.properties since multiple managed beans can be defined to different Connections instances.