REST API Timeout | Community
Skip to main content
ishanishah
Level 2
May 10, 2019

REST API Timeout

  • May 10, 2019
  • 3 replies
  • 13826 views

Hi Team,

We are calling an API endpoint from Adobe Campaign Java script activity by using :

var http = new HttpClientRequest(<Our API URL>) and the request is timing out before it could get a response from the End point/API (timing out at approximately 5 mins),

Is there any attribute in server config file which would set the timeout value to a higher number > 5 mins? OR

Do we have to add timeout attribute in the code itself. Do you have a sample code to share?

Thanks,

Ishani

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

Venu_Reddy
Level 6
May 10, 2019

Hello Ishani,

Try the following

  1. var http = new HttpClientRequest("yourhost.com"
  2. http.execute() 
  3. var response = http.response 
  4. for(var i in response.header) 
  5.   logInfo("header[" + i + "] => " + response.header[i]) 

Should give you something like

js3 header[Date] => Wed, 05 Jul 2017 10:10:13 GMT

js3 header[Server] => Apache/2.2.22 (Debian)

js3 header[Vary] => Accept-Encoding

js3 header[Content-Length] => 291

js3 header[Keep-Alive] => timeout=5, max=100

js3 header[Connection] => Keep-Alive

js3 header[Content-Type] => text/html; charset=iso-8859-1  

You can use the following code as well

var API = 'http://yourwebserviceendpoint.com'

var http = new  HttpClientRequest(API);

http.method = "GET";

http.header["Content-Type"] = "application/json";

http.header["Accept"] = "application/json";

http.header["Authorization"] = "Basic Z3XNlbmRleHRlc3QxQGdtYWlsLmNvbTpsb2dpbjEyMzQ="; // replace with your authorization code

http.execute();

var response = http.response;

Regards,

Venu

ishanishah
Level 2
May 10, 2019

Thanks Venu.

We are able to send the request but it seems to time out after 5 minutes. My questions is - How do we increase the time out to 10 mins instead?

Venu_Reddy
Level 6
May 10, 2019

Hello Ishani,

The default connect timeout for outgoing http connection is 5sec.

You can change the connection timeout in server.conf file using the attribute value http_connect_timeout.

Click here for more details http://docs.graylog.org/en/3.0/pages/configuration/server.conf.html#web-rest-api

Regards,

Venu

Jean-Serge_Biro
Level 10
May 10, 2019

Hi Isha,

Please change your serverConf.xml file, the section with urlPermission to allow outgoing connection.

This is documented in section "Outgoing connection protection" in this documentation:

Configuring Campaign server

It was added about 2 years ago in a build for security reasons.

Regards
J-Serge

Jean-Serge_Biro
Level 10
May 10, 2019

Hi Isha,

Moreover, you should always use:
try{

     <your code>

}

catch(e){

     logWarning("Error number: " + e );
}

so the timeout message would have been much more clearer.
Same for other kind of errors.

Then you have a look in the web.log file (on mta server or on applicative server depending on the pbject type) to read the error details.

Regards
J-Serge