Outbound REST API special character not passing ?

sukran
Mega Sage

Try to Test the REST API variable substitutions of special character (%) , its returns 500 error

and If we remove % , its inserted correctly

Its outside application issue where we inserting the record? or ServiceNow Issue?

 

find_real_file.png

3 REPLIES 3

Narsing1
Mega Sage

Hi,

It is the issue with the special character.  Please use Escape type as with escape instead of "No escaping"

Thanks,

Narsing

@Narsing tried but same error

Mahendra RC
Mega Sage

Hello Sukran,

I am not sure on how you can pass the % in Rest message via variable substitution but if you try to call the Rest Message API via script and then pass the data that include % character in request body then it will not give an error. Please refer to the below script:
var requestBody = {"name": "ServerTesting1%"}; is the request body set in the below example and the Server is created with ServerTesting1% name in target instance.

(function () {
	var tableName = "cmdb_ci_server";
	var requestBody = {"name": "ServerTesting1%"};
	var RESOURCE_PATH = "/api/now/table/cmdb_ci_server";
	var request = new sn_ws.RESTMessageV2();
	request.setEndpoint("https://<YOUR_INSTANCE_URL>.service-now.com/"+RESOURCE_PATH );
	request.setHttpMethod('POST');
	//request.setQueryParameter("sysparm_query", "name=ApplicationServerHelpdesk");

	//Eg. UserName="admin", Password="admin" for this code sample.
	var user = 'admin'; //replace your user name here
	var password = 'admin'; // replace user's password here
	request.setBasicAuth(user,password);

	//gs.print(JSON.stringify(requestBody));
	request.setRequestBody(JSON.stringify(requestBody));

	request.setRequestHeader("Accept","application/json");
	var response = request.execute();
	var responseBody = response.getBody();
	gs.print(responseBody);
})();

Please mark my respsone as helpful/correct, if it answer your question.

Thanks