{"action":"closed","issue":{"url":"https://api.github.com/repos/Selvaga/Yammer-Admin-Scripts/issues/4","repository_url":"https://api.github.com/repos/Selvaga/Yammer-Admin-Scripts","labels_url":"https://api.github.com/repos/Selvaga/Yammer-Admin-Scripts/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/Selvaga/Yammer-Admin-Scripts/issues/4/comments","events_url":"https://api.github.com/repos/Selvaga/Yammer-Admin-Scripts/issues/4/events","html_url":"https://github.com/Selvaga/Yammer-Admin-Scripts/issues/4","id":354305382,"node_id":"MDU6SXNzdWUzNTQzMDUzODI=","number":4,"title":"Add Members to Yammer Group","user":{"login":"Selvaga","id":41688112,"node_id":"MDQ6VXNlcjQxNjg4MTEy","avatar_url":"https://avatars0.githubusercontent.com/u/41688112?v=4","gravatar_id":"","url":"https://api.github.com/users/Selvaga","html_url":"https://github.com/Selvaga","followers_url":"https://api.github.com/users/Selvaga/followers","following_url":"https://api.github.com/users/Selvaga/following{/other_user}","gists_url":"https://api.github.com/users/Selvaga/gists{/gist_id}","starred_url":"https://api.github.com/users/Selvaga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Selvaga/subscriptions","organizations_url":"https://api.github.com/users/Selvaga/orgs","repos_url":"https://api.github.com/users/Selvaga/repos","events_url":"https://api.github.com/users/Selvaga/events{/privacy}","received_events_url":"https://api.github.com/users/Selvaga/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":{"login":"Selvaga","id":41688112,"node_id":"MDQ6VXNlcjQxNjg4MTEy","avatar_url":"https://avatars0.githubusercontent.com/u/41688112?v=4","gravatar_id":"","url":"https://api.github.com/users/Selvaga","html_url":"https://github.com/Selvaga","followers_url":"https://api.github.com/users/Selvaga/followers","following_url":"https://api.github.com/users/Selvaga/following{/other_user}","gists_url":"https://api.github.com/users/Selvaga/gists{/gist_id}","starred_url":"https://api.github.com/users/Selvaga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Selvaga/subscriptions","organizations_url":"https://api.github.com/users/Selvaga/orgs","repos_url":"https://api.github.com/users/Selvaga/repos","events_url":"https://api.github.com/users/Selvaga/events{/privacy}","received_events_url":"https://api.github.com/users/Selvaga/received_events","type":"User","site_admin":false},"assignees":[{"login":"Selvaga","id":41688112,"node_id":"MDQ6VXNlcjQxNjg4MTEy","avatar_url":"https://avatars0.githubusercontent.com/u/41688112?v=4","gravatar_id":"","url":"https://api.github.com/users/Selvaga","html_url":"https://github.com/Selvaga","followers_url":"https://api.github.com/users/Selvaga/followers","following_url":"https://api.github.com/users/Selvaga/following{/other_user}","gists_url":"https://api.github.com/users/Selvaga/gists{/gist_id}","starred_url":"https://api.github.com/users/Selvaga/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Selvaga/subscriptions","organizations_url":"https://api.github.com/users/Selvaga/orgs","repos_url":"https://api.github.com/users/Selvaga/repos","events_url":"https://api.github.com/users/Selvaga/events{/privacy}","received_events_url":"https://api.github.com/users/Selvaga/received_events","type":"User","site_admin":false}],"milestone":null,"comments":0,"created_at":"2018-08-27T12:49:49Z","updated_at":"2018-09-24T08:29:33Z","closed_at":"2018-09-24T08:29:33Z","author_association":"OWNER","body":"## INPUT ## \r\n$YAMToken = Read-Host -Prompt \"YAMMER TOKEN\"   # How to Get Yammer Token [CLICK HERE ](https://github.com/Selvaga/Yammer-Admin-Scripts/issues/1)\r\n$groupid = Read-Host -Prompt \"Group ID\"  #Where you want to add members\r\n$inputfile = Read-Host -Prompt \"Input file path \"   #Input file will have only yammer user email addresses separated by line space\r\n\r\n## Execution ## \r\n$members = Get-Content -Path $inputfile \r\nWrite-Host \"----------------- Output ----------------\"  \r\n\r\nforeach ($UserEmail in $members) \r\n{\r\ntry\r\n    {\r\n        $UserReq = Invoke-WebRequest -uri (New-Object System.Uri(\"https://www.yammer.com/api/v1/users/by_email.json?email=$UserEmail\")) -Method GET -Headers $headers\r\n        $code = $UserReq.StatusCode\r\n    }\r\ncatch\r\n    {\r\n        Write-Host $UserEmail \" - Invalid User Account\" -ForegroundColor DarkYellow\r\n    }\r\n\r\nif ($code -eq 200)\r\n    {\r\n        $UserData = ConvertFrom-Json $UserReq.Content \r\n        $userid = $UserData.ID\r\n        $basicAuthValue = \"Bearer \"+$YAMToken \r\n        $headers = @{ Authorization = $basicAuthValue } + @{ Host = \"www.yammer.com\" } + @{ \"Content-Type\" = \"application/x-www-form-urlencoded; charset=UTF-8\" } \r\n        $body = \"group_id=$groupid&user_id=$userid\" \r\n        $str=\"https://www.yammer.com/api/v1/group_memberships\" \r\n        $uri=New-Object System.Uri($str) \r\n        try\r\n        { \r\n            $MemList = Invoke-WebRequest -uri $uri -Method Post -Headers $headers -Body $body \r\n            $code = $MemList.StatusCode \r\n        } \r\n        catch \r\n        {\r\n            $code = \"404\" \r\n            Write-Host $userid \"Invalid - \" $code \r\n        }  \r\n        if ($code -eq 200) \r\n        { \r\n            Write-Host $userid \"Already Member - \" $code \r\n        } \r\n        if ($code -eq 201) \r\n        { \r\n            Write-Host $userid \"Added - \" $code \r\n        } \r\n    }\r\n}"}}
{"actor":{"display_login":"Selvaga"}}