Forum Discussion

ronaksomani's avatar
9 years ago

http.client.request to make a POST call to external API from lithium

Hi,

 

I am using http.client.request freemarker object to make a POST call to an external API from Lithium endpoint. I am using basic auth to authenticate the call. 

Request looks as below :

http.client.request("https","api.something.com","url.something").header("Authorization", "Basic encodedcreds").body("{'param1':'value1','param2':'value2'}","application/json")post() />

 

But I am getting connect time out error in response as:  "error making http request: connect timed out"

 

I have already added the allowed domain name to http.client in Admin.

Additionaly I would like to know how can I pass additional Header attributes in request (more then 1). 

Can someone help ?

 

  • Hey ronaksomani,

     

    To answer your second question, you can just chain .header calls to add multiple headers, so something like:

     

    http.client.request("https","api.something.com","url.something").header("Authorization", "Basic encodedcreds").header("header2", "header2value").body("{'param1':'value1','param2':'value2'}","application/json").post() />

    As for the timeout, how long does your http request take if you do a curl request to the same endpoint you are trying to hit with http.client? Our default timeout is 5 seconds, so if it takes longer to get a response then it will timeout. We can increase it for you, but depending on your use case, you may not want to have the endpoint take longer than that.

     

    Hope this helps,

     

    Yuri

3 Replies

  • Could you check with support on the timeout issue, it does happen with endpoints sometime, they can configure this.
  • ronaksomani's avatar
    ronaksomani
    Mentor
    9 years ago

    Thanks VarunGrazitti. For time out I will check with support team, but how can I add mutiple header attributes to request?

  • YuriK's avatar
    YuriK
    Khoros Expert
    9 years ago

    Hey ronaksomani,

     

    To answer your second question, you can just chain .header calls to add multiple headers, so something like:

     

    http.client.request("https","api.something.com","url.something").header("Authorization", "Basic encodedcreds").header("header2", "header2value").body("{'param1':'value1','param2':'value2'}","application/json").post() />

    As for the timeout, how long does your http request take if you do a curl request to the same endpoint you are trying to hit with http.client? Our default timeout is 5 seconds, so if it takes longer to get a response then it will timeout. We can increase it for you, but depending on your use case, you may not want to have the endpoint take longer than that.

     

    Hope this helps,

     

    Yuri