Kelby Madal
Kelby Madal

Reputation: 11

Yammer "Follow in Inbox" API support

My company has created a Yammer application that we use internally. Our app automatically subscribes people to various threads that have been created. We have found that there is a difference between "subscribing" someone to a thread and what happens when a user clicks the "follow in inbox" link on the site. When we automatically subscribe people, the only thing that we can see happening is that the thread will appear in the users "Following" section in the Home tab. Contrast this with what happens when a user clicks the "Follow in Inbox" link. From that point on any comments added to the thread will show up in the user's inbox and an email will be sent out to the user when this happens. We would really like for this to happen when we automatically subscribe someone to a thread, however, this feature seems to be missing from the REST API. Does anyone know of a way to accomplish this? The functionality provided by the subscription API endpoint is not sufficient for our purposes.

Thank you

P.S. I've sent the link to this question to several of my colleges they may respond before I get a chance to.

Upvotes: 0

Views: 219

Answers (1)

Shep
Shep

Reputation: 628

As a verified admin it is possible to create an impersonation token and then perform actions on behalf of the user such as join group/thread.

Note that for private groups, the group admin's are still required to approve the new member

https://developer.yammer.com/docs/impersonation

You can achieve your desired behaviour by adding users directly to the groups.

A C#.Net example I use:

// Impersonate user to join group                           
string ClientID = ConfigurationSettings.AppSettings["ClientID"]; // ClientID of custom app.
string userid = XMLDoc.Root.Element("response").Element("id").Value; // Yammer user id (in this case retreived from a previous API query)
string YammerGroupID = "123456"; // set group id.
string url = "https://www.yammer.com/api/v1/oauth/tokens.json?user_id=" + userid + "&consumer_key=" + ClientID; // impersonation end-point
HttpWebRequest request;
request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("Authorization", "Bearer " + bearer); // Bearer token of verified admin running the custom app.
request.Timeout = 90000;
request.Method = "GET";
request.ContentType = "application/json";
request.Proxy = new WebProxy() { UseDefaultCredentials = true };
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    using (Stream responseStream = response.GetResponseStream())
    {
        StreamReader reader = new StreamReader(responseStream);
        string UserTokenJSON = reader.ReadToEnd(); // UserOAuth token as a JSON string.                                                                
        string UserToken = UserTokenJSON.Substring(UserTokenJSON.IndexOf("token") + 8, 22); // Find 'token' in json string.
        string temp = UserToken.Substring(UserToken.Length); // there is likely a much better way to parse out the token value, although this works.
        temp = UserToken.Substring(UserToken.Length - 1);
        temp = UserToken.Substring(UserToken.Length - 2);
        if (UserToken.Substring(UserToken.Length) == "\\")
        { UserToken = UserToken.Substring(0, UserToken.Length); }
        if (UserToken.Substring(UserToken.Length - 1) == "\"")
        { UserToken = UserToken.Substring(0, UserToken.Length - 1); }
        if (UserToken.Substring(UserToken.Length - 2) == "\",")
        { UserToken = UserToken.Substring(0, UserToken.Length - 2); }
        string url2 = "https://www.yammer.com/api/v1/group_memberships.json?group_id=" + YammerGroupID; // group membership endpoint, 
        HttpWebRequest request2;
        request2 = (HttpWebRequest)WebRequest.Create(url2);
        request2.Headers.Add("Authorization", "Bearer " + UserToken); // Impersonation Token
        request2.Timeout = 90000;
        request2.Method = "POST";
        request2.ContentType = "application/json";
        request2.Proxy = new WebProxy() { UseDefaultCredentials = true };
        try
        {
            using (WebResponse response2 = (HttpWebResponse)request2.GetResponse())
            {
                confirmedstring += "  New member: " + Email + "\\r\\n"; // This is used for posting summary back to a Yammer group in further code.
                confirmedadditions++;
            }
        }
        catch
        {
            Errorstring += "Error in adding " + Email + " to group " + YammerGroupID + "\\r\\n";
            errors++;
        }
    }
}

Upvotes: 0

Related Questions