Issues calling script using REST api

Hey everyone,
I am trying to run a PowerShell script which calls a customer One Identity Script leveraging the REST api. One Identity V7.1.2 is used. At the variable $newUri the PowerShell script throws out an Authorization Issue:

Code:
--Setting authentication--
$authdata = @{AuthString="Module=DialogUser;User=<user>;Password=<password>."}
$authJSON = ConvertTo-JSON $authdata -Depth 2

--Login against the Application server--
Invoke-RestMethod -Uri "https://<servername>/d1imappserver/auth/apphost" -Body $authJSON.ToString() -Method Post -UseDefaultCredentials -Headers @{Accept="application/json"} -SessionVariable $wsession

--> Issue starts here
$newURI = (Invoke-RestMethod -Uri "https://<servername>/D1IMAppServer/api/script/CCC_xxxx_REST_FinalizeServiceRequest" -WebSession $wsession -Method Post -ContentType application/json).uri

--Logout--
Invoke-RestMethod -Uri "https://<servername>/d1imappserver/auth/logout" -WebSession $wsession -Method Post

ErrorMessage:
Invoke-RestMethod : Snapshot of ExecuteScriptRequest generated by ServiceStack on 05.12.2017 10:44:46
view json datasource from original url: https://<servername>/D1IMAppServer/api/script/CCC_xxxx_REST_FinalizeServiceRequest? in other
formats: json xml csv jsv
This reports json data source
Close Window Response StatusError CodeUnauthorizedMessageNot authorized
At line:2 char:12
+ $newURI = (Invoke-RestMethod -Uri "https://<servername> ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand


Can anyone support in this case?

 

Thanks in advance,

Niko

Parents Reply
  • Execution sequence for calling script via REST API

    $cred=Get-Credential
    $authdata=@{AuthString="Module=DialogUser;User=abc;Password=abc"}
    $authJson=ConvertTo-Json $authdata -Depth 2
    Invoke-RestMethod -Uri "https://<baseurl>/AppServer/auth/apphost" -Body $authJson.ToString() -Method Post -Credential $cred -Headers @{Accept="application/json"} -SessionVariable wsession

    Output: 

    claims : @{schemas.oneidentity.com/.../identifier=abc; http://schemas.oneiden
    tity.com/ws/2017/04/identity/claims/useruid=CCC-A025329ED8C4F043B78B4B0C45004D97;
    schemas.oneidentity.com/.../module=DialogUser;
    schemas.oneidentity.com/.../product=;
    schemas.oneidentity.com/.../isdialogadmin=true}
    passwordBased : True
    moduleDisplay : System user
    sessionId : ILb26jRNIrTXnBUlhrZ2
    userName : abc

    Next Command:

    $body=@{parameters=@("IE0","23455")} | ConvertTo-Json

    {
    "parameters": [
    "IE0",
    "23455"
    ]
    }

    Invoke-RestMethod -Uri "https://<baseurl>/AppServer/api/script/CCC_LookupSiteCode_SNOW" -WebSession $wsession -Method PUT -Body $body -Headers @{Accept="application/json"}

     

    Output:

    Invoke-RestMethod : {"responseStatus":{"errorCode":"ArgumentException","message":"Method expected 2 parameters but got
    0.","errors":[]}}
    At line:1 char:1
    + Invoke-RestMethod -Uri "ashsd95030.vbechtel.com/.../api ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
    eption
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

Children