and more in a single search tool across platforms. Read the announcement here. |
03/25/2024 01:18 PM - edited 03/26/2024 06:59 AM
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
03/26/2024 11:21 PM
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.
03/27/2024 07:11 AM - last edited on 03/27/2024 11:37 PM by Sunil
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]
03/27/2024 08:21 PM
Mandatory parameters to API are not sent
04/02/2024 11:47 AM
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.
04/02/2024 07:44 PM
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