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

REST PS Connector - Unable to pass single quotes as value

RanjithSaiM
New Contributor
New Contributor

Hi,

I have a PowerShell script executed from Saviynt using REST. One of the variables which holds a key value is stored in the connection JSON and sent to the script as a dynamic variable.

The issue is basically when I have the variable in connection JSON with a single quote and space the code breaks. Is there any way I can escape space and single quotes while passing it as a value to the PowerShell script.

Sample value stored in the JSON, - I'm Spartan

The single quotes is throwing error because it is considered as a start parameter for string in PowerShell and it is expecting another single quotes for closure. The space is causing an issue as it is separating the value and the second part after the space is considered as unknown parameter.

Here is the connection JSON,

{
"authentications": {
"acctAuth": {
"authType": "Basic",
"url": "https://removed/SaviyntApp/PS/executepsscript ",
"httpMethod": "POST",
"httpParams": "{\"Script\": \"cd C:\\\\\\\\PowerShell_Scripts\\\\\\\\Saviynt_EIC\\\\\\\\HelloVoIP.ps1\"}",
"httpHeaders": {},
"httpContentType": "application/x-www-form-urlencoded",
"properties": {
"userName": "testUsername",
"password": "testPassword"
},
"expiryError": "Couldn't authenticate you",
"authError": [
"Couldn't authenticate you"
],
"timeOutError": "Read timed out",
"errorPath": "error",
"maxRefreshTryCount": 5,
"tokenResponsePath": "name",
"tokenType": "Basic",
"accessToken": "Basic asdfghjkl",
"PS_Secret": "I'm spartan"
}
}
}

Here is the import JSON with the dynamic parameter from connection JSON,

{
"accountParams": {
"connection": "acctAuth",
"processingType": "SequentialAndIterative",
"statusAndThresholdConfig": {
"deleteLinks": false,
"accountThresholdValue": 30,
"correlateInactiveAccounts": false,
"inactivateAccountsNotInFile": false,
"deleteAccEntForActiveAccounts": true
},
"call": {
"call1": {
"callOrder": 0,
"stageNumber": 0,
"http": {
"url": "https://<customerServerName>/SaviyntApp/PS/executepsscript",
"httpParams": "{\"Script\": \"cd C:\\\\\\\\PowerShell_Scripts\\\\\\\\Saviynt_EIC\\\\\\\\TestScript.ps1 -PS_Secret ${connection.PS_Secret}\"}",
"httpHeaders": {
"Authorization": "${access_token}"
},
"httpContentType": "application/x-www-form-urlencoded",
"httpMethod": "POST"
},
"listField": "",
"keyField": "accountID",
"colsToPropsMap": {
"accountID": "name~#~char",
"name": "name~#~char",
"status": "status~#~char"
},
"disableDeletedAccounts": true
}
}
}
}

I have highlighted the variables used in the JSON as Bold to make it easier.

I have tried escaping using the backslashes like we do for double quotes and slash but, could not get it working. Let me know if anyone has tried and had it working.

Thanks!

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

6 REPLIES 6

rushikeshvartak
All-Star
All-Star

You can change secret and remove single quote


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

@rushikeshvartakthat is not an option, this secret is linked to every record that is being maintained. Almost 5000 users are linked with this code word. Customer will not be touching users records just because Saviynt cannot pass single quotes.

There has to be a way to escape it, I just do not know how.

Saathvik
All-Star
All-Star

@RanjithSaiM : Change the content type to application/x-www-form-urlencoded-pws and see if that works

if not try below logic as well

-PS_Secret ${connection.PS_Secret.replace(''', '\\\\\'')} instead of -PS_Secret ${connection.PS_Secret}


Regards,
Saathvik
If this reply answered your question, please Accept As Solution and give Kudos to help others facing similar issue.

RanjithSaiM
New Contributor
New Contributor

@Saathvikthank you for the suggestion. I think the 5 back slashes are breaking the JSON format as shown below.

RanjithSaiM_0-1714155353441.png

I have tried adding another slash which fixes the formatting error but, sends blank value to the script.

Doing a replace was a great idea if we can get it working. This is will be useful for the regular REST API calls.

Another point I wanted to highlight is when the script is throwing exception, it is actually printing the dynamic variables used in the URL from the connectionJSON in the logs. I feel this beats the purpose of hiding the values in the connectionJSON as attributes.

${connection.PS_Secret.replace('''', '\\\\\'')}


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

RanjithSaiM
New Contributor
New Contributor

@rushikeshvartakit matches to what @Saathvik  has sent and it breaks the code.

I got something working which is basically encode storing the encoded value in the connectionJSON and then only decode it in the PowerShell script.

ConnectionJSON value:

"PS_SharedSecret": "I%27m%20batman"

PowerShell code:

[uri]::UnescapeDataString("$PS_SharedSecret")