Getting Online Now Presence from the Yammer REST API

This post will show you the options for getting presence information (Online Now status) from the Yammer REST API.

Overview

Online Now

The Online Now feature of Yammer is driven by Yammer’s own REST API. In this post, I’ll show you the calls available to get presence information for use in your own applications.

Some parameters and endpoints shown below are not officially documented by Yammer – expect that these may change at any time.

The AutoComplete API

The AutoComplete endpoint has an undocumented parameter, presence=true, that you can use to get presence information for particular users.

The AutoComplete api is used to provide type-ahead for searches, #hashtags, and @mentions, but is also a great way to quickly get detailed user information. To get the presence information for a specific user, you can use the short username and pass it in as the prefix parameter.

5/1/2014 – REST APIs accessed through the JS SDK should use the https://api.yammer.com/api/v1 url instead of https://www.yammer.com/api/v1. The AutoComplete api is currently an exception however, and will only respond to https://www.yammer.com/api/v1/autocomplete/ranked

.

Autocomplete doesn’t guarantee an exact match with users (it won’t match an email address or user id), so be sure you request more than one result, and inspect the length/count of objects returned to make sure you find the right one.

If you want to get a bunch of users, you can leave the prefix empty and specify a large number:

If you want to get the same list of users that appears in the Online Now box on the Yammer web site, you can use another undocumented parameter: secondOrderRanks=true. You will most likely want to use this with the includePendingUsers=false parameter as well:

Any of the variations above will return a JSON object with a presence property. Values are “online”, “offline”, “idle”, and “mobile”.

Presence - AutoComplete

The Users API

The Users API is another endpoint you can use to get presence information. Many of the user endpoints will honor an undocumented parameter, include_presence=true.

The User API calls that currently work with the include_presence parameter are:

The include_presence parameter does not work with the following User API calls:

Presence - User API

Search

The search api doesn’t seem to return presence at this time.

Whoville – Getting and Updating Status

Another undocumented API endpoint Yammer internally uses to get and set status is /api/v1/whoville. Unfortunately you can’t access this from the Javascript SDK (the endpoint throws Access-Control-Allow-Origin errors in the browser, and I suspect that it is only wired to work with requests from an Origin of www.yammer.com).

A typical GET request for status looks like the following:

You can request the status for multiple users (separated with commas), and it will return JSON similar to the following:

This is the endpoint that the Yammer web UI uses to periodically poll for status changes.

To update status, Yammer internally uses another endpoint:

Calling this endpoint with an HTTP POST will update the user’s status to ONLINE. I’ve tried experimenting with different parameters at the end, such as /idle, /mobile, and /offline, but the only one that I was able to use to any effect was /online.

To call this endpoint, it appears you need to have Accept: */* and Content-Type: application/json in your request headers. It also only appears to be able to update the current user’s status (I haven’t tried it with a verified admin token).

Summary

Hopefully this brief tour of the Presence options in the Yammer API gives you some ideas to start thinking about integrating Yammer Presence in your applications. And hopefully the API matures a bit and becomes officially supported and with more features.

3 comments on “Getting Online Now Presence from the Yammer REST API
  1. Great article.

    I’m trying to use the the autocomplete functionality and had it working at one time. Since the new API that was introduced in April, I’ve been getting same origin policy errors on this function only. I believe it has something to do with using the old URLs. Do you have any advice on how to get around this?

    Thanks.

Comments are closed.