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

Chuck Tomasi
Tera Patron

Have you tried replacing the slashes with /



If it's passing them as part of the URI, which it may, then they could be getting the URI garbled.


You can use the method



var string2 = gs.urlEncode(string1);



to convert a lot of this stuff before putting it in your parameters.


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.


Good to know Prici! I should have remembered the alternate methods to setStringParameter(). Thanks for sharing.



You may want to consider marking your response as correct so that others with the same question in the future can find it quickly and that it gets removed from the Unanswered list.



If you are viewing this from the community inbox you will not see the correct answer button.   If so, please review How to Mark Answers Correct From Inbox View.



Thank you