Avaya Support Forums

Avaya Support Forums (http://support.avaya.com/forums/index.php)
-   Small and Medium Business Communications (http://support.avaya.com/forums/forumdisplay.php?f=6)
-   -   IPO 11 REST API with Powershell (http://support.avaya.com/forums/showthread.php?t=14407)

drueneuve 01-14-2021 08:32 AM

IPO 11 REST API with Powershell
 
Hi all
Does anybody have a sample code to run GET methode with powershell
I succed with authentication but the GET return error 401 unauthorized
Authentication
Code:

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$uri = "https://<IPAddress_IPO>:7070/WebManagement/ws/sdk"
$authente = "/security/authenticate"
$IPAdress = "/admin/v1/provisionIPAddress"

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

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

$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

Result :
Status : 1
Error :
Request
Code:

$response2 = Invoke-restmethod -method GET -Uri ($uri+$IPAdress) -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

Result :
Status : 0
Error : 401:UnAuthorized
I have check that $tokenSDK contain cookies JSESSIONID, I don't understand how to maintain the session !

drueneuve 01-22-2021 12:36 AM

The problem was the "group management api" must have "Web services/configuration read/write" enable. With that setting, the code above is Ok


All times are GMT -7. The time now is 12:44 PM.