How to do REST interaction with local server to ServiceNow instance using Mid Server.

Hemant13
Kilo Contributor

Hi There, My requirement is to interact(CRUD) with local server(installed on my local windows machine) with ServiceNow instance through REST calls.

What I Did:

  • Installed Mid Server on my local machine where my server is running, then started the MidServer with my SNOW instance credentials which worked fine.
  • On SNOW instance validated the same in Mid Server and validated in Credentials module.
  • Also successfully tested and fetched (GET) data with Outbound Rest Message call from my local server.

What I want:

I have written a workflow which does CRUD operation on my server and when I am trying to connect through my module(workflow) it fails to connect to my server and does nothing and gives below error:

 java.net.ConnectException: Connection refused (Connection refused) when posting to <REST>

 

I am new to SNOW and would like to know do I need any further configuration in order to make this connectivity work for my modules.

 

Note: I tried same without MidServer by installing my server on GCP and using that GCP Public IP in SNOW and which worked fine. So my workflow is fine.

 

Please let me know if you need any other clarification. 

 

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Is the MID server specified in the REST API script?

If user/password was wrong, it'll give an authentication error so it's probably with not being able to find ip/port. Was the code generated from REST Message? Need to see the code to comment further.

 

EDIT: The generated code comments out the MID Server setting so it's necessary to remove the "//" and set the MID server name.

//set a MID server name if one wants to run the message on MID
r.setMIDServer('MY_MID_SERVER');

View solution in original post

4 REPLIES 4

Hitoshi Ozawa
Giga Sage
Giga Sage

Is the MID server specified in the REST API script?

If user/password was wrong, it'll give an authentication error so it's probably with not being able to find ip/port. Was the code generated from REST Message? Need to see the code to comment further.

 

EDIT: The generated code comments out the MID Server setting so it's necessary to remove the "//" and set the MID server name.

//set a MID server name if one wants to run the message on MID
r.setMIDServer('MY_MID_SERVER');

Thanks Hitoshi,

I was able to do the Outbound Rest Message test successfully but was not sure that I have to introduce mid server to my code as well in order to make the connection complete.

After introducing the mid server it was able to connect through my server through mid server and REST call worked.

Thanks for the response. 🙂

KK-2020
Mega Contributor

can you share how you setup teh MID server? 

Jamsheer1
Tera Guru

The error message looks like a connectivity issue. Your local network do not have a direct connectivity to your instance and it could be via via proxy or any other way. Such cases you need to configure REST via MID Server in order to do so if you are using Outbound REST Message then specify the MID Server details in the outbound REST message or in a script as setMidServer parameter as above .  

Kindly refer the docs to start with the outbound integrations.

https://docs.servicenow.com/bundle/paris-application-development/page/integrate/outbound-rest/concept/c_OutboundRESTWebService.html