- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2020 08:41 AM
Hello all,
I have the following REST API call inside my script include.
However, instead of this call, I want to configure a call to the third system through a MID server.
At first I created a new MID Server on my instance with all the needed information (name "myMID")
How can I use this MID server inside my code?
My code is the following:
var r=new sn_ws.RESTMessageV2();
//endpoint
r.setEndpoint("aURL"); //set a url endpoint (third system's endpoint)
r.setHttpMethod("post"); //HTTP method
//set the queryParameters (the first parameter is the name of the parameter that the third system is waiting for)
r.setQueryParameter("id",id); //id is passed from catalog client script
r.setQueryParameter("t",t); //t is passed from catalog client script
var response=r.execute(); //send the REST API call
var responseBody=response.getBody(); //receive back the response
var answer=JSON.parse(responseBody);
...
How can send this call from the MID server??
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 02:37 AM
Hi,
Points below
You are not able to connect to that API from Postman since it is in client's network
1) I configured the MID server on my instance and I put it in the http request tab of an outgoing message. Do I need to make anything else?
- The MID Server should be in client's internal network and you should check by hitting the endpoint of API when you login to MID Server to confirm if mid server can reach. If not get client's network team involved and allow MID Server machine's IP address to be reaching to that client API
2) I guess I need somehow to install the mid server on the client's network? Am I right?
- Yes
3) To make the call, I just need to use the outbound message that uses the mid server?
- Yes; ensure you first test the endpoint from mid server
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 02:11 AM
Hi Smith,
You need to ask the concerned team managing the MID server to allow access to the third party application and relax any firewall rules. In the script, you just need to add the below the line.
r.seMIDServer('MID SERVER NAME'); //active MID server name that has access to the external application
Hope that helps!
Regards,
Muhammad
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 02:16 AM
Hey
thank you so much for your reply.
Since I am new to integrations, I would kindly ask you if you could clarify what you meant by the following "You need to ask the concerned team managing the MID server to allow access to the third party application and relax any firewall rules."
My case is also the following, so if you would like you could share your knowledge to my case.
I have SN instance that I want to communicate via a post method to a third system.
If I just make a simple post call with postman to the endpoint of the third system, I do not get neither a http status code nor a response.
Could it be because in postman I do not use a mid server but I make a direct call to the third system?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-19-2020 02:45 AM
If the third-party system is available to use without a VPN or accessible outside the client's network then you are not required to use the MID server and its vice versa.
To troubleshoot the postman case you mentioned. Check the following.
- The protocol being used in the endpoint is correct. i.e. HTTP or HTTPS
- Check with network administrator for any firewall rules in place.
- If you are using variables or path parameters with your request, make sure the final address is structure correctly by opening the Console, which will display the URL your request was sent to when it executed. Unresolved request variables can result in invalid server addresses.
- check postman timeout settings. May be request is timing out before completion.
I would suggest try making a rest call directly from the Servicenow Rest method and see what you get. You can do this by opening your REST method and under the related link click on TEST ui action.
Muhammad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2020 03:15 AM
Hey again
do I need also from my code in script include (it makes the rest call to the third system), to set a waitForResponse() method?
Since I am making a post method to the third system, but I am waiting also for a response from the third system.
Should I also do it with executeAsync() ??
For example it needs to look like the following, since I am waiting for a response?
var r=new sn_ws.RESTMessageV2();
//endpoint
r.setEndpoint("a URL");
r.setHttpMethod("post"); //method
r.setQueryParameter("id",id);
r.setMIDServer("mymid");
var response=r.execute(); //should it be executeAsync() ??
r.waitForResponse(); // do I need this line, since I am waiting for response ??
responseBody=response.getBody();
Since I am "new" to integrations with MID server, your knowledge should be valuable for me.
Thank you in advance.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-20-2020 03:33 AM
Hey Smith - if you need the response right away and based on the response you need to further process then you can go with execute() method. This will be a synchronous method.
Using waitingForResponse() with executeAsync() will make it work like execute() method.
I will suggest reading through below kb article for detailed information.
https://hi.service-now.com/kb_view.do?sysparm_article=KB0716391
Muhammad