How To Get All Yammer Messages In A Specific Thread Using PowerShell

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.

  1. # Input Parameters    
  2. $developerToken = "461-*****YOkutfuKoWUEmWPg"    
  3. $threadID="1138117349"    
  4. $headers = @{ Authorization=("Bearer " + $developerToken) }      
  5.     
  6. Function GetMessages($pageNo)    
  7. {    
  8.     #page parameter- Programmatically paginate through the messages in the network.   
  9.     $uri="https://www.yammer.com/api/v1/messages/in_thread/" + $threadID +".json?page=" + $pageNo    
  10.     
  11.     # Invoke Web Request    
  12.     $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers    
  13.     
  14.     # Check whether the status code is 200    
  15.     if ($webRequest.StatusCode -eq 200) {    
  16.         
  17.         # Converts a JSON-formatted string to a custom object or a hash table.     
  18.         $results = $webRequest.Content | ConvertFrom-Json  
  19.     
  20.         # Loop through all the messages    
  21.         $results.messages | ForEach-Object {    
  22.             $message = $_     
  23.             # Display all the messages    
  24.             Write-Host -ForegroundColor Green $message.id ": body - plain: " $message.body.plain    
  25.         }    
  26.     
  27.         # Check if there are more items available    
  28.         if($results.more_available)    
  29.         {    
  30.             GetMessages($pageNo+1)    
  31.         }            
  32.     }    
  33.     else {    
  34.         Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status    
  35.     }    
  36. }    
  37.     
  38. # Call the function    
  39. GetMessages(1)    

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – MessagesinThread.ps1 file location

Run the following command.

  1. >.\MessagesinThread.ps1

Thus, in this blog, you saw how to get all Yammer messages in a specific thread using PowerShell.