Patrick Lamber

Patrick Lamber - Apr 28, 2017 - Follow          
Technical consultant and Office Server and Services MVP.

Manage the group memberships using the Yammer REST API and PowerShell

by Patrick Lamber on Apr 28, 2017
Filed under: Yammer Governance Scripts Office 365
Share it:

This post will show how to use the Yammer REST API for managing the group memberships of a group. You can find the documentation of the Yammer REST API here.

You can generate the baerer token as described in this post.
Always consider the REST API and Rate Limits when accessing a Yammer network.

Add a member to a group

You can use the snippet below to add a new member to a group. The group id can be retrieved using the techniques explained in a previous post.

$baererToken = "Put your baerer token here"
$yammerBaseUrl = "https://www.yammer.com/api/v1"

Function Get-BaererToken() {
    $headers = @{ Authorization=("Bearer " + $baererToken) }
    return $headers
}

$headers = Get-BaererToken
$urlToCall = "$($yammerBaseUrl)/group_memberships.json"
Write-Host $urlToCall
$userBody = @{ group_id = "putYourGroupIdHere"; email="putYourEmailAddressHere" }
Invoke-WebRequest –Uri $urlToCall –Method Post -Headers $headers -Body $userBody

Leave a group

You can leave a group by using the script below.

$baererToken = "Put your baerer token here"
$yammerBaseUrl = "https://www.yammer.com/api/v1"
$groupId = "Put your groupId here"

Function Get-BaererToken() {
    $headers = @{ Authorization=("Bearer " + $baererToken) }
    return $headers
}

$headers = Get-BaererToken
$urlToCall = "$($yammerBaseUrl)/group_memberships.json?group_id=$($groupId)"
Write-Host $urlToCall
Invoke-WebRequest –Uri $urlToCall –Method Delete -Headers $headers
by Patrick Lamber on Apr 28, 2017
Filed under: Yammer Governance Scripts Office 365
Share it: