HTTP Request getting timed out after 5 minutes using the invoke code activity

HTTP Request getting timed out after 5 minutes using the invoke code activity.
The request is bringing in response from Postman but when same request is passed using the invoke code activity then after 5 minutes the response code 0 is returned.

Custom code:
try
{
var client = new RestSharp.RestClient(in_API_URL);
var request = new RestSharp.RestRequest(RestSharp.Method.POST);
request.AddHeader(“Content-Type”, “application/json”);

var filePath = in_doc_str;
var docType = in_doc_str_type;
var fileName = in_file_name;
var customerName = in_customer_name;

var inputValue = “{"doc_str":"”+filePath+“","doc_str_type":"”+docType+“","file_name":"”+fileName+“","customer_name":"”+customerName+“"}”;

request.AddParameter(“application/json”,inputValue, ParameterType.RequestBody);
request.Timeout = 1080000;
client.Timeout = 1800000;

IRestResponse response = client.Execute(request);

Console.WriteLine(response.Content);
out_ResponseCode = response.StatusCode.ToString();
out_ResponseContent = response.Content;
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}

We also tried using the async coding technique but that too isn’t working:
async System.Threading.Tasks.Task MakeRequestAsync()
{
var client = new RestSharp.RestClient(in_API_URL);
client.Timeout = -1;

   var request = new RestSharp.RestRequest( RestSharp.Method.POST);

request.AddHeader("Content-Type", "application/json");

var filePath = in_doc_str;
var docType = in_doc_str_type;
var fileName = in_file_name;
var customerName = in_customer_name;

var inputValue = “{"doc_str":"”+filePath+“","doc_str_type":"”+docType+“","file_name":"”+fileName+“","customer_name":"”+customerName+“"}”;
Console.WriteLine(inputValue);
request.AddParameter(“application/json”,inputValue, ParameterType.RequestBody);

IRestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);

}

Can someone provide a way to increase the timeout when we try to access API endpoint using UiPath studio, since it is already working with Postman.

@utkarsh.khandelwal,

Any specific reason to not use HTTP Request? I mean why to reinvent the wheel :thinking:

Thanks,
Ashok :slight_smile:

The API endpoint is hosted on internal environment and no auth token is required.
If we try to use the Http request activity then it doesn’t work for us and gives us error message of invalid input. Hence we tried using the custom code and it is working for us when the input file is small in size and it fails due to timeout after 5minutes when the input file size is large.

@utkarsh.khandelwal,

Ohh ok got it. Have you tried to do pagination if supported by API endpoint. This way we can do multiple requests to get chunks of data which will be retrieved within 5 mins of timeout as well.

Thanks,
Ashok :slight_smile:

I used request.ReadWriteTimeout property and set its value higher than 5 minutes and it worked.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.