We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

WHY is the Rest Message URL being truncated?

lonesoac01
Giga Guru

Hello all,

 

    I am able to use the below code in a lower Dev environment just fine.  I move the code up to an IT environment, and I am seeing the StringParameter being contatenated to: https://dingdongs.net/v1/cb_link  Please note, that I was originally using the "setStringparameterNoEscape" and the same thing is happening.  I commented out both "setStringParameter" and "setStringparameterNoEscape" and ServiceNow did not use any URL at all, which was expected.  So, I know that my code is using this string value, there is just something I am missing.

 

 

var r = new sn_ws.RESTMessageV2('qualtrics', 'POST');
//gs.log(body,"REST API TESTING"); // Testing purpose need to comment this line
r.setStringParameterNoEscape('interactionRecord', body);
var qualtricsURL = gs.getProperty('qualtrics.API.URL');
//Development Env
r.setStringParameter('endpoint', 'https://dingdongs.net/v1/cb_link?jobId=123&apiKey=123');
//Prod Env
//r.setStringParameterNoEscape('endpoint', qualtricsURL);
var response = r.execute();
var responseBody = response.getBody();
//gs.log('STRY0750821 ' + body);
var httpStatus = response.getStatusCode();
//gs.log(httpStatus,"REST API TESTING");  // Testing purpose need to comment this line

 

 Thank you.

8 REPLIES 8

Maybe a backslash \ to escape it in your code?  

r.setStringParameter(
  "endpoint",
  "https://dingdongs.net/v1/cb_link\?jobId=123&apiKey=123"
);

Amit Pandey
Mega Sage

Hi @lonesoac01 

 

I think when you set parameters using setStringParameter(), ServiceNow will URL encode them, which might cause issues with certain characters like &.Can you try this once- 

 

var r = new sn_ws.RESTMessageV2('qualtrics', 'POST');
r.setStringParameterNoEscape('interactionRecord', body);
var qualtricsURL = gs.getProperty('qualtrics.API.URL');
r.setStringParameterNoEscape('endpoint', 'https://dingdongs.net/v1/cb_link?jobId=123&apiKey=123');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();

 

 

I tried the above code and the URL is still being truncated. 

r.setStringParameterNoEscape('endpoint', 'https://dingdongs.net/v1/cb_link?jobId=123&apiKey=123');

I then tried just removing the question mark from the endpoint and the URL was no longer truncated.

r.setStringParameterNoEscape('endpoint', 'https://dingdongs.net/v1/cb_linkjobId=123&apiKey=123');

I even tried escaping the question mark with a backslash as someone else on this string suggested and it was still truncated.

 

I am thinking that there might be a system setting or something that I just do not know about.

Hi @lonesoac01 

 

Lets break the URL into multiple parts, concatenating them together. Can you try this-

var endpoint = 'https://dingdongs.net/v1/cb_link' + '?jobId=123' + '&apiKey=123';
r.setStringParameterNoEscape('endpoint', endpoint);

 

Regards,

Amit