Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Outbound Rest Message using get method

salu
Mega Guru

Hello,

I have used below background script to test the functionality and getting the below error.

What need to be checked from the endpoint url?

(function sample_http_request() {

      try {

              var request = new sn_ws.RESTMessageV2();

              request.setHttpMethod('get');

              request.setEndpoint('http://localhost:8080/xxx?id=1234');

              var response = request.execute();

              var httpResponseStatus = response.getStatusCode();

              var httpResponseContentType = response.getHeader('Content-Type');

              var parser = new global.JSONParser();

              var parsed = {};

              var httpResponseBody;

              gs.debug("http response status_code: " + httpResponseStatus);

              gs.debug("http response content-type: " + httpResponseContentType);

              //   if request is successful then parse the response body

              if (httpResponseStatus == 200 && httpResponseContentType == 'application/json') {

                      httpResponseBody = response.getBody();

                      //   parse JSON string returned from request into a json object

                      parsed = parser.parse(httpResponseBody);

                      // iterate over JSON object only printing the id property of JSON objects in results array

                      for (var i = 0; i < parsed.results.length; i++) {

                              gs.print('id: ' + parsed.results[i].id)

                      }

              }

      }

      catch (ex) {

              var message = ex.getMessage();

              gs.debug(message);

      }

})();

find_real_file.png

7 REPLIES 7

Hi Saranya,



Changing to correct credentials does it work. Please reply back in case of issues.



Regards


Param


Hi saranya s babu,



status_code==401 means, credentials issue



Please click helpful,correct answer,like



Thanks,


Raminaidu


swati38
Tera Expert

Hi Saranya.



This must be authentication issue.



Thanks,


Swati