View Single Post
  #1  
Old 01-14-2021, 09:32 AM
drueneuve drueneuve is offline
Aspiring Member
 
Join Date: Dec 2020
Posts: 2
drueneuve has 10 reputation points
Default 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 !

Last edited by drueneuve; 01-14-2021 at 09:36 AM.
Reply With Quote