Announcing the Saviynt Knowledge Exchange unifying the Saviynt forums, documentation, training,
and more in a single search tool across platforms. Read the announcement here.

createrequest error using API example

jcarlone
New Contributor II
New Contributor II

Hello,

I'm using the PowerShell example for Fetch Request History Details found at https://documenter.getpostman.com/view/1797923/RWaLwo21?version=latest (Access Request > Request History > Fetch Request History Details) and I'm having some issues getting it to work.

I took the example call from the documentation and swapped the token, requestkey, URL, and path for my own environmental variables. However, all I receive in response is "The remote server returned an error: (412) Precondition Failed." with no other information.

Has anyone had success using this example call in PowerShell?

 

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", "Bearer {{token}}")

$multipartContent = [System.Net.Http.MultipartFormDataContent]::new()
$stringHeader = [System.Net.Http.Headers.ContentDispositionHeaderValue]::new("form-data")
$stringHeader.Name = "requestkey"
$stringContent = [System.Net.Http.StringContent]::new("387")
$stringContent.Headers.ContentDisposition = $stringHeader
$multipartContent.Add($stringContent)

$body = $multipartContent

$response = Invoke-RestMethod '{{url}}/ECM/{{path}}/fetchRequestHistoryDetails' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json

 

5 REPLIES 5

adarshk
Saviynt Employee
Saviynt Employee

Please validate the access provisioned to the account that is used to perform these operations. 

error: (412) Precondition Failed is indicating that the access is denied. 

jcarlone
New Contributor II
New Contributor II

Hi Adarshk, 

The login being used for the API call has the ROLE_ADMIN  Sav role.

[This message has been edited by moderator to disable URL]

rushikeshvartak
All-Star
All-Star

Mandatory parameters to API are not sent


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.

Hi rushikeshvartak,

I understand there's some parameter or format missing from the call, my question is what that missing thing might be. The call I listed is from the Saviynt API documentation, so I'm not sure what else it might need without guessing.

Your PowerShell script appears to be mostly correct. However, the Invoke-RestMethod cmdlet in PowerShell expects the body to be directly passed as a parameter, rather than as part of the headers. Here's the corrected version of your script:

 

$headers = @{
"Authorization" = "Bearer {{token}}"
}

$body = @{
requestkey = "387"
}

$response = Invoke-RestMethod -Uri '{{url}}/ECM/{{path}}/fetchRequestHistoryDetails' -Method 'POST' -Headers $headers -Body $body
$response | ConvertTo-Json


Regards,
Rushikesh Vartak
If you find the response useful, kindly consider selecting Accept As Solution and clicking on the kudos button.