Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Powershell sample API REST 2

Status
Not open for further replies.

Darvid

Systems Engineer
Jan 19, 2021
2
FR
Hi all
I'm trying to query IPO 11 REST API with a powershell script but I'm stuck on an error 401:unauthorized !
This is my test script
Code:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$uri = "[URL unfurl="true"]https://<serveur>:7070/WebManagement/ws/sdk"[/URL]
$authente = "/security/authenticate"
$huntgroups = "/admin/v1/huntgroups?ipaddress=<IP_Solution_node>"

$Text = "SDKUser:password"
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($Text)
$credentials = [Convert]::ToBase64String($Bytes)
#$credentials

$headers = @{                            
    "X-User-Client" = "Avaya-WebAdmin"
    "X-User-Agent" = "Avaya-SDKUser"
    "Content-Type" = "application/xml"
    "Authorization" = "Basic " + $credentials
}

$response1 = invoke-restmethod -method GET -Uri ($uri+$authente) -sessionvariable tokenSDK -Headers $headers -SkipCertificateCheck
write-host "Status : " $response1.response.status
Write-host "Error  : " $response1.response.data.ws_object.SMAError.error.error_code
Status : 1
Error :
Code:
$response2 = Invoke-restmethod -method GET -Uri ($uri+$huntgroups) -Headers $headers -WebSession $tokenSDK -SkipCertificateCheck -MaximumRedirection 0

write-host "Status : " $response2.response.status
Write-host "Error  : " $response2.response.data.ws_object.SMAError.error.error_code
Status : 0
Error : 401:UnAuthorized

It looks that I'm correctly authenticated in the first request and session info are passed in $tokenskd otherwise I got an error 461:SessionTimeout
Thanks for reading.. and more for help :)
David
 
Does the service user have the Web Services > Service Monitor Read permission? That's the only thing I know about this.
 
The problem was the "group management api" must have "Web services/configuration read/write" enable. With that setting, the code above is Ok
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top