Yammer from C# – create a group

There’s a surprisingly woeful lack of doco and information about using the API for Yammer – from C# especially – there’s more for the JavaScript way, but not for .NET.

The one I need – to create a Yammer Group – is this one :


The best approach is to simply call the REST API – using the .NET Web Client classes (HttpWebRequest).

It follows that you need to do a POST to this URL – the clincher is to define an ‘accessToken’ to do so.   This is like a SharePoint 2013 style ClientId/ClientSecret.

Click here to register your app, and get the token – it is then registered against YOUR Yammer network.   


You’ll get a CLIENTID and CLIENTSECRET – need to plug these into the following URL >


And then you’ll get a CODE value.    THEN, need to call the following >


And you’ll get a TOKEN – which is the magic bean you need for the following C# code.

Here’s some doco about it >

Then – you can just call the following method within C# :

private static string PostYammerJson(string url, string accessToken)
    //make the request
    string json = null;
    HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
    request.Method = “POST”;
    request.Headers.Add(“Authorization”, “Bearer” + ” ” + accessToken);
    using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
        Encoding encode = Encoding.GetEncoding(“utf-8”);
        StreamReader reader = new StreamReader(response.GetResponseStream(), encode);
        json = reader.ReadToEnd();
    return json;

Within the C# code – I can then do this :

string postUrl = “https://www.yammer.com/api/v1/groups.json?name=CoolPeople&private=false”;

//replace with what you get from Yammer register App page

string accessToken = “1234567890qwertyuiop”;     

PostYammerJson(postUrl, accessToken);

This is a GREAT pattern – thanks to the folk at the Microsoft PnP on GitHub.

There’s a whole solution/project that does this – and a LOT more – great examples :



One thought on “Yammer from C# – create a group

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s