Rest Variable substitutions

tsoct
Tera Guru

I need to send two dynamic parameters to the endpoint for querying. I confirmed that the token works properly. However, it returns no value, and when debugging, the endpoint remained unchanged without a value passed. 

 

 

 

getACTIVITY2: function() {
        try {
            var r = new sn_ws.RESTMessageV2('CPNYCostCenter', 'Get ACTIVITY');
            r.setStringParameterNoEscape('p_fund', 'AF'); //Hardcode for now to debug
            r.setStringParameterNoEscape('p_org', 'CSIPM'); //Hardcode for now to debug
			r.setRequestHeader('Authorization', 'Bearer ' + this.token);

            var response2 = r.execute();
            var responseBody2 = response2.getBody();
            var httpStatus2 = response2.getStatusCode();
			gs.info("The Activity: " + responseBody2); //return empty
                        gs.info("Endpoint: " + r.getEndpoint();) // return https:url.com//ServiceNow/getActivityList?p_org=${p_org}&p_fund=${p_fund} //Variable value did not pass into the endpoint
        } catch (ex) {
            var message = ex.message;
        }
    },

 

 

 

tsoct_0-1715755006844.png

 

1 ACCEPTED SOLUTION

kente
Tera Guru

You are posting the query parameters twice

kente_0-1715767052022.png


If you do that you will get them twice

kente_1-1715767100666.png

If using the HTTP Query Parameters you should not add anything in the path. It will add "?" as well as the parameters you hav added

View solution in original post

9 REPLIES 9

dgarad
Giga Sage

Hi @tsoct 

what do you get the status code?

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Hello @dgarad ,

ResponseStatus: 200

 I added content-type = application/json in the HTTP Method. And the activity now return

*** Script: The Activity: <HTML>
<HEAD>
<TITLE>Error 415--Unsupported Media Type</TITLE>
</HEAD>
<BODY bgcolor="white">
<FONT FACE=Helvetica><BR CLEAR=all>
<TABLE border=0 cellspacing=5><TR><TD><BR CLEAR=all>
<FONT FACE="Helvetica" COLOR="black" SIZE="3"><H2>Error 415--Unsupported Media Type</H2>
</FONT></TD></TR>
</TABLE>
<TABLE border=0 width=100% cellpadding=10><TR><TD VALIGN=top WIDTH=100% BGCOLOR=white><FONT FACE="Courier New"><FONT FACE="Helvetica" SIZE="3"><H3>From RFC 2068 <i>Hypertext Transfer Protocol -- HTTP/1.1</i>:</H3>
</FONT><FONT FACE="Helvetica" SIZE="3"><H4>10.4.16 415--Unsupported Media Type</H4>
</TD></TR></TABLE>
</BODY>
</HTML>

In the rest messages in the HTTP header add content-type = application/json.

dgarad_1-1715758715652.png

 

dgarad_0-1715758642493.png

 

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Hi @dgarad , 

Added and the message i got:

*** Script: The Activity: <HTML>
<HEAD>
<TITLE>Error 415--Unsupported Media Type</TITLE>
</HEAD>
<BODY bgcolor="white">
<FONT FACE=Helvetica><BR CLEAR=all>
<TABLE border=0 cellspacing=5><TR><TD><BR CLEAR=all>
<FONT FACE="Helvetica" COLOR="black" SIZE="3"><H2>Error 415--Unsupported Media Type</H2>
</FONT></TD></TR>
</TABLE>
<TABLE border=0 width=100% cellpadding=10><TR><TD VALIGN=top WIDTH=100% BGCOLOR=white><FONT FACE="Courier New"><FONT FACE="Helvetica" SIZE="3"><H3>From RFC 2068 <i>Hypertext Transfer Protocol -- HTTP/1.1</i>:</H3>
</FONT><FONT FACE="Helvetica" SIZE="3"><H4>10.4.16 415--Unsupported Media Type</H4>
</TD></TR></TABLE>
</BODY>
</HTML>