REST call via mid server debugging

erikbos
Giga Contributor

Hi,

I am trying to setup a REST call to retrieve data from an internal application via the midserver. I have defined the webserver via the UI and use JS to make the call and use the predefined webservice. In the WS definition for the GET method I have set the mid server to use.

At the moment I am just interested in making the call itself and do not care yet about parsing the json response yet: I am trying it with a few lines of code to log whether the call itself was successful or not.

var r = new sn_ws.RESTMessageV2('Device42', 'get');
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.log(httpStatus);

The code executes but hangs and I need to terminate it.

In the ECC queue I see an entry for every attempt I have done so far so I think the API call request gets queued for the mid server. An ECC queue entry contains the following XML as content:

<?xml version="1.0" encoding="UTF-8"?>

<parameters>

  <parameter name="message_headers" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;fields/&gt;"/>

  <parameter name="message_parameters" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;fields/&gt;"/>

  <parameter name="source" value="X"/>

  <parameter name="name" value="get"/>

  <parameter name="rest_user" value="............."/>

  <parameter name="rest_password" value="enc:...................."/>

</parameters>

On the mid server in the logs I do not see anything related to REST messages, this API end point, etc: like it did not receive this ecc queue entry at all. (I have set 'debug.logging' to true).  


Doing the API call by hand using curl on the mid server works fine so connectivity from the mid server to the internal application is ok.

Any idea how I debug this any further?

1 ACCEPTED SOLUTION

silas1
ServiceNow Employee
ServiceNow Employee

Erik, one thing I notice in the log is that the rest message appears to be null:


REST Msg Outbound - RESTMessageClient : Executing: Outbound REST Message/Method: null/get


Are you sure you're accessing the Rest message correctly by name? One thing to keep in mind, if this is part of a scoped application you might need to reference the rest message by it's scoped name e.g. "x_acme_myapp.Device42".


View solution in original post

6 REPLIES 6

erikbos
Giga Contributor

Hi Silas, the problem was actually much more simple than I thought: I tried a few options (creating the RESTMesssageV2 object myself, or using the one you configure via the UI).




The console debug information led me down the wrong path and somehow the first REST requests appeared to be "stuck" in the ECC queue. While looking at the input/output timestamps it shows they got half an hour after the REST-request was requested. (A mid server restart fixed that.)




In the end I did end up with a working script without noticing 😉 Oops, thanks for your help!


silas1
ServiceNow Employee
ServiceNow Employee

Glad you were able to figure it out Erik! If the REST message debugging was not as helpful to you in figuring out this issue, I'm curious if anything about the debug info could have been changed to make it more helpful? Or is something missing altogether?