Search This Blog

Friday, October 16, 2015

Add user to Yammer group and approve the added user in private group

Pre-requisite

1. Service account with Verified admin credentials
2. Create a app and follow the steps in this link - https://developer.yammer.com/docs/test-token
3. Client id and token (oAuth token) of verified admin is mandatory.
4. Service account has to be group admin to approve the members if only those approved by an admin is selected.

Please find the link to download the working code. client id, oAuth token of verified admin of your network needs to be updated along with the user email id and the group id to which the user has to be added.

Step 1: https://www.yammer.com/api/v1/users/by_email.json?email={0} - returns user id from the user id. If you have user id handy you can ignore this step.

Step 2: https://www.yammer.com/api/v1/oauth/tokens.json?consumer_key={0}&user_id={1} - Impersonate the user and get the oAuth token after impersonation. Below diagram explains the request flow.

Note: Above diagram is taken from the book - Develop on Yammer: Social Integration for Modern Business Applications -  By Pathik Rawal, Pryank Rohilla 

Step 3: https://www.yammer.com/api/v1/group_memberships.json?group_id={0} - Make a post call to add the user to the group with the impersonated token as Authentication - Bearer token.

Step 4: https://www.yammer.com/api/v1/group_memberships.json?group_id={0}&user_id={1}&approve=1 - Make a post call with the group admin - oAuth token to approve the request.

Step 4 is not documented in Yammer API but it works. At any point of time, it can go unsupported.

This link contains end to end project - Completed demo