I’m trying to query a list of users by team_ids using PowerShell’s Invoke-RestMethod. Unfortunately, the body, which declares team_ids = is returning an error:
{“error”:{“message”:“Invalid Input Provided”,“code”:2001,“errors”:[“Team ids must be a Array.”]}}
Here’s the code:
<#------------USERS------------#>
$apiRoot = “https://api.pagerduty.com/users”
$headers = New-Object “System.Collections.Generic.Dictionary[[String],[String]]”
$headers.Add(“Accept”, ‘application/vnd.pagerduty+json;version=2’)
$headers.Add(“Authorization”, ‘Token token=InsertTokenHere’)
$body = @{
‘limit’ = ‘100’
‘team_ids’= @(‘PZYAW28’)
}
$contentType = “application/json”
$users = Invoke-RestMethod -Uri $apiRoot -ContentType “application/json” -Method Get -Header $headers -Body $body
$userArray = @()
Foreach ($user in $users.users){
$psObject = New-Object -TypeName PSObject
$psObject | Add-Member -MemberType NoteProperty -Name userName -Value $user.name
$psObject | Add-Member -MemberType NoteProperty -Name userEmail -Value $user.email
$psObject | Add-Member -MemberType NoteProperty -Name userTimeZone -Value $user.time_zone
$psObject | Add-Member -MemberType NoteProperty -Name userRole -Value $user.role
$psObject | Add-Member -MemberType NoteProperty -Name userID -Value $user.id
$userArray += $psObject
}
$userArray | Sort userName | Format-Table
When I run this without the team_ids specified in the body, I get results. I also tried:
$body = @{
‘limit’ = ‘100’
‘team_ids’= @(‘PZYAW28’)
} | ConvertTo-Json
Which stores the following in the $body variable:
{
“limit”: “100”,
“team_ids”: [
“PZYAW28”
]
}
But I get this error from PowerShell:
Invoke-RestMethod : Cannot send a content-body with this verb-type.
I appreciate any help!