Forum Discussion

Joe_Williams's avatar
7 years ago
Solved

Update hostGroupIds With Rest API

I have the below code which results in a 401. Any ideas? I am attempting to update the hostGroupIds.   $status = $null $body = $null $response = $null <# Use TLS 1.2 #> [Net.ServicePoin...
  • Joe_Tran's avatar
    7 years ago
    On 5/10/2018 at 5:44 PM, Joe Williams said:

     

    
    [...]
    $data = '{"hostGroupIds":"187,258"}'
    [...]
    <# Make Request #>
    $response = Invoke-RestMethod -Uri $url -Method $httpVerb -Header $headers 
    [...]

     

    Hi, Joe. You are including a data payload in your authorization signature, but not including it in your REST call. So when the API is checking your REST call against the signature, it doesn't match and you'll get authentication-like errors. 

     Your $data is already a properly formatted JSON string, so you can just add the -Body argument, like this. 

    $response = Invoke-RestMethod -Uri $url -Method $httpVerb -Header $headers -Body $data