How to make a REST API call through a MID Server?

Smith Johnson
Tera Guru

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??

1 ACCEPTED SOLUTION

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

45 REPLIES 45

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

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Smith Johnson 

Let me know if I have answered your question.

If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

@Ankur Bawiskar Hey Ankur,

until now I was looking how to test the endpoint through MID server as you told me to do so.

However, I couldn't find it.

You have mentioned the following:

"you should check by hitting the endpoint of API when you login to MID Server to confirm if mid server can reach"

How can I check it? Could you please guide me through this?

 

Thank you in advance Ankur and for your time too.

Hi,

You must be having an endpoint for the API

Try to open browser in mid server machine and hit the URL

Does it give you any error or so

You can also try to use Chrome Advanced Rest Client extension to test from Chrome browser

Advanced REST client

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hey @Ankur Bawiskar ,

based on the first reply that you gave me, in the article it says about waiForResponse method. 

Since I am making a post method to the third system, but I am waiting also for a response from the third system, do I need the waitForResponse() method?

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.