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

JSON - how to escape space

asp
Regular Contributor
Regular Contributor

Hi,

While creating accounts with a REST connector (for servicenow), we need to make multiple calls to fetch sys_ids for certain attributes, before the call to create account. Sample JSON looks like this - 

"accountIdPath": "call4.message.result.sys_id",
"responseColsToPropsMap": {},
"call": [{
"name": "call1",
"connection": "acctAuth",
"url": "https://abc.service-now.com/api/now/table/cmn_department?sysparm_query=name=${user.costcenter}&sysparm_fields=sys_id",
"httpMethod": "GET",
"httpParams": "",
"httpHeaders": {
"Authorization": "${access_token}"
},
"httpContentType": "application/json",
"successResponses": {
"statusCode": [
200,
201
].................................

.............................

 

The part is bold is the user's cost-center and this call works if the cost-center does not have a space in it. But it fails if there is a space in the name of the cost-center. 

How can I escape name=${user.costcenter} portion of the JSON, to handle cases where cost center can contains spaces?

 

Thanks

2 REPLIES 2

SB
Saviynt Employee
Saviynt Employee

Can you try using ${encodeURIComponent(user.costcenter)} in the url.

This should encode the special characters in the url for the attribute costcenter.

 


Regards,
Sahil

mayankshah
New Contributor III
New Contributor III

Can you use the below code?

url": "http://xxxxxxxxx?${URLEncoder.encode(user.costcenter, \"UTF-8\").replace(\"+\", \"%20\")}"

This should parse all the special characters including space.