Introducing "API Quirks", the Series (Today: Yammer External Networks)

Mike Knoop
Mike Knoop / October 25, 2012

Introducing "API Quirks"

Everyone at Zapier has to deal with API Quirks. We deal with so many APIs each day, we have become almost immune to the often bizarre, undocumented, frustrating behavior exhibited by web APIs. Our goal with this series is to document some of the most time-consuming things we run into. Considering the short-form nature of many solutions (and the amount of quirks we run into), you can expect this series to grow quickly!

Naturally, most of the content will be time-sensitive. No API or documentation is static. Take any quirks published before "today" with a grain of salt!

Yammer External Networks

Yammer, a Facebook-like product for the enterprise, allows users to join several networks (maybe a work network, and professional network). There is always a primary network which the default OAuth access_token will allow you access to.

The Yammer API documentation is not clear about how you go about reading or writing to an External Network which the current authorized user has access to. It is actually easy:

  • You'll need to have already performed the standard Yammer OAuth song-and-dance to obtain the base accecss_token for the user. Next, request a list of access_tokens for all External Networks associated with the currently authorized user.

    GET https://www.yammer.com/api/v1/oauth/tokens.json?access_token=…

  • The returned results will be a list of dictionaries. There may be duplicate access_tokens per network. You will likely want to de-duplicate off of network_id or network_permalink to end up with only one valid access_token per External Network. Assuming the JSONified contents of the above URL exist in the variable json, you can do something like (Python):

    external_networks = []
    
    def ids(external_networks):
        ret = []
        for each in external_networks:
            ret.append(each.get('network_id', None))
        return ret
    
    for each in json:
        if each.get('network_id', None) not in ids(external_networks):
            network = {
                'network_permalink': each.get('network_permalink', None),
                'network_name': each.get('network_name', None),
                'network_id': each.get('network_id', None),
                'token': each.get('token', None),
            }
            external_networks.append(network)
    
    print external_networks # [{...}, {...}]
    

… to obtain a final array of External Networks and their associated access_tokens

  • Use any of the associated access_tokens like you normally would, with no change to the URL structure you used to access non-External Network API endpoints, like

    GET https://www.yammer.com/api/v1/messages.json?access_token=…

Don't want to worry about this? Use Yammer Triggers and Actions on Zapier

Get Productivity Tips In Your Inbox

Learn about workflow, company building, and how to get things done.

Load Comments...

Comments powered by Disqus

Workflow

Take the Work out of Workflow

Zapier is the easiest way to automate powerful workflows with more than 1,500 apps.