In this blog, you will see how to get all Yammer messages in a specific thread using PowerShell.
Prerequisites
Go to https://www.yammer.com/client_applications and register an app.
Once the app is registered, generate a developer token.
Copy the below script and paste it in a Notepad. Save the file as MessagesinThread.ps1.
- # Input Parameters
- $developerToken = "461-*****YOkutfuKoWUEmWPg"
- $threadID="1138117349"
- $headers = @{ Authorization=("Bearer " + $developerToken) }
-
- Function GetMessages($pageNo)
- {
- #page parameter- Programmatically paginate through the messages in the network.
- $uri="https://www.yammer.com/api/v1/messages/in_thread/" + $threadID +".json?page=" + $pageNo
-
- # Invoke Web Request
- $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers
-
- # Check whether the status code is 200
- if ($webRequest.StatusCode -eq 200) {
-
- # Converts a JSON-formatted string to a custom object or a hash table.
- $results = $webRequest.Content | ConvertFrom-Json
-
- # Loop through all the messages
- $results.messages | ForEach-Object {
- $message = $_
- # Display all the messages
- Write-Host -ForegroundColor Green $message.id ": body - plain: " $message.body.plain
- }
-
- # Check if there are more items available
- if($results.more_available)
- {
- GetMessages($pageNo+1)
- }
- }
- else {
- Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status
- }
- }
-
- # Call the function
- GetMessages(1)
Open PowerShell window and run the following command.
folderlocation – MessagesinThread.ps1 file location
Run the following command.
Thus, in this blog, you saw how to get all Yammer messages in a specific thread using PowerShell.