REST API - Resolution for PASWS168E "Invalid Parameters" Error when calling the Idira PVWA REST API to cache SSH keys
Symptom
When using a PowerShell script to invoke the SSHKeys/Cache endpoint, the following error is returned:
{
"Details": [
{
"ErrorCode": "PASWS168E",
"ErrorMessage": "Input parameter for [formats] value is invalid",
"ParameterName": "formats"
}
],
"ErrorCode": "PASWS167E",
"ErrorMessage": "There are some invalid parameters"
}
Environment
12.2;12.6;14.0;14.2;14.4;14.6;15.0 Privileged Access Manager (PAM, self-hosted) Cyber-Ark API/SDK Cyber-Ark API/SDK REST API
Cause
The error is primarily caused by one or both of the following:
-
Incorrect Parameter Name: The API expects
formats(plural) rather thanformat(singular) when requesting specific key types. -
Incorrect Data Type: The
formatsparameter must be passed as an array of strings (enclosed in square brackets[]), even if only one format is requested. -
Missing Key Password: For certain formats like OpenSSH or PPK, a
keyPasswordparameter is required in the request body.
Resolution
Correct Request Body Structure
To successfully retrieve an OpenSSH or PPK key, the JSON body must include the formats array and a keyPassword.
Example JSON Body:
{
"formats": ["OpenSSH"],
"keyPassword": "YourPassword Here"
}
PowerShell Implementation
Update your PowerShell script to define the body as a multi-valued object before converting it to JSON. This ensures the correct array structure is maintained.
# Parameters
$PVWA_URL = "https://your-pvwa-url/"
$AuthToken = "Your-Auth-Token"
# Define the body with plural 'formats' and required 'keyPassword'
$Body = @{
formats = @("OpenSSH")
keyPassword = "YourPasswordHere" # Required for OpenSSH/PPK formats
} | ConvertTo-Json
# REST Call
$response = Invoke-RestMethod -Method Post `
-Uri "$PVWA_URL/PasswordVault/API/Users/Secret/SSHKeys/Cache" `
-Headers @{ Authorization = $AuthToken } `
-ContentType "application/json" `
-Body $Body
# Extract the specific key from the response value array
$openSshKey = ($response.value | Where-Object { $_.format -eq "OpenSSH" }).privateKey
Additional Considerations
-
Default Behavior: If you use the singular
formatparameter or omit theformatsarray, the API may default to providing the private key in PEM format. -
Multiple Formats: You can request multiple formats at once by adding them to the array:
"formats": ["OpenSSH", "PPK", "PEM"]. -
Access Denied: If you encounter an
UnauthorizedAccessExceptionwhen saving the key, ensure the execution context has write permissions to the destination folder (e.g.,C:\temp\).