- 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
‎12-01-2020 02:46 PM
The best way is to do the validation in Flow Designer or Workflow too. It's being done in OOTB ServiceNow forms like Incident.
Some user want a real-time check during form so I may also do the check onChange but I always have a check in my flow too.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-29-2024 11:59 PM - edited ‎09-30-2024 12:05 AM
Hi @Ankur Bawiskar ,
I am trying to make a REST API call from ServiceNow to a third party using mid server. I don't know what authentication details need to be passed in the code as mid server uses kerberos authentication. My code is as below:
var requestBody;
var responseBody;
var status;
var sm;
try{
sm = new sn_ws.RESTMessageV2(); // Might throw exception if message doesn't exist or not visible due to scope.
sm.setEndpoint("http://xyz.xyy.com:8080/authorize");
sm.setHttpMethod("get");
sm.setQueryParameter("user","abc");
sm.setQueryParameter("action","approve");
sm.setQueryParameter("eonid","7011");
sm.setQueryParameter("component","change");
sm.setLogLevel('all');
sm.setRequestHeader("Accept","Application/json");
sm.setEccParameter('skip_sensor', true);
sm.setMIDServer('mscore_1');
response = sm.executeAsync(); // Might throw exception if http connection timed out or some issue with sending request itself because of encryption/decryption of password.
response.waitForResponse(60); // In seconds. Wait at most 60 seconds to get response from ECC Queue/Mid Server //Might throw exception timing out waiting for response in ECC queue.
responseBody = response.haveError() ? response.getErrorMessage() : response.getBody();
status = response.getStatusCode();
} catch(ex) {
responseBody = ex.getMessage();
status = '500';
} finally {
requestBody = sm ? sm.getRequestBody():null;
}
gs.info("Request Body: " + requestBody);
gs.info("Response: " + responseBody);
gs.info("HTTP Status: " + status);
On running above script , I am getting below output:
Script: Request Body: {"user" : "abc","action" : "approve","eonid" : "7011","component" : "change"}
Script: Response: ECC message execution denied (rejecting rule ID: ecc_fw_rule_dc5f8a67)
Script: HTTP Status: 0
Mid server used is up and running in ServiceNow. can you please guide on what wrong am I doing and also if I need to mention any authentication details in the code since I am using kerberos authentication.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 12:02 AM
@Ankur Bawiskar I wanted to mention u for above question, mentioned wrong person. Can you please help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-30-2024 12:20 AM
I am client here in this REST API call as I am making request to 'GET' details from the third party system. Mid server is up and running on myside but still I am not able to get the desired response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-02-2020 01:26 AM
Thank you so much Ankur for all the support and all your responses to my questions.
You have helped me a lot to understand how I can make a REST call through a MID server.
Thanks again,
Smith.