REST API - setQueryParameter with front slash not working

Tamil5
Tera Expert

Hi All,

I am trying to get data from external resource using REST call.

When I set parameter with '/' is not working. Getting response as 0, but it contains data.

sm.setHttpMethod("get");

sm.setEndpoint("https://<application.doamin.com>/api/v1/locations/${date_updated_since,active,type_id,region}");

sm.setRequestHeader("Accept", 'application/json');

sm.setRequestHeader("Content-Type", "application/json; charset=UTF-8");

sm.setRequestHeader("key","<my key value>");

sm.setQueryParameter("date_updated_since", '2016-04-04');

sm.setQueryParameter("active", 1);

sm.setQueryParameter("type_id", 1);

sm.setQueryParameter("region", "NA/EU/APAC"); // the api call works fine without this parameter

This query return records without region, but if I add region parameter then it returns 0.

But I'm sure that records are available with this value.

I assume this front slash is causing the issue.

Even I tried escape character (with back slash) but no use.

Any help.

Thanks

Prici

1 ACCEPTED SOLUTION

Hi Chuck,



Thank you for your response.


Tried giving '/' but got the same response (error).



But the below statement solved my issue.


'sm.setStringParameterNoEscape("region", "NA/EU/APAC");'




Thanks


Prici.


View solution in original post

7 REPLIES 7

Sure Chuck..Marked the correct answer..


Thank you


Ankur Bawiskar
Tera Patron
Tera Patron

Hi Prici,



When you set some parameter using GET it goes in URL and if you are using special characters such as space, slash etc you need to send URL encoded values for these


example:


space %27


slash /



For your reference


HTML URL Encoding Reference



Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.


Thanks


Ankur


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

I tried '/' Ankur, but sadly it was not working for me.