How to retry Rest Caller Task based on Response Status

One of the common patterns that is being asked for is to retry Rest Caller Task based on response status. For example, you might want to retry the task for 4xx or 5xx errors at max 5 times. Or maybe want to have a different retry strategy for different sets of response status. Here is how it could be achieved:

You would need to create two integrations:

  1. Sub Integration: Which would execute rest caller task
  2. Main Integration: Which would call sub integration based on conditions

Sub Integration
Here is how sub integration would look like:

 

Screenshot 2023-07-31 at 9.14.42 AM.png

Screenshot 2023-07-31 at 9.15.47 AM.png

This integration creates two variables:

  1. retryCounter: Integer variable which is the input and output variable for the integration.
  2. responseCode: Integer variable which is the output variable for the integration.

Other output variables are optional.

This integration would work as follows:

  1. The integration would be called via api trigger and would accept an integer called retryCounter in input payload.
  2. The retryCounter would be incremented by one.
  3. Rest caller task would be executed and its response code would be extracted.

Note: Make sure to set Task should fail on HTTP error as False on rest caller task.

Pro Tip: If you want to configure the retry interval, you can add Timer Task after Api Trigger and configure it in combination with retryCounter.

Main Integration
Here is how main integration would look like:

Screenshot 2023-07-31 at 9.23.51 AM.png

Screenshot 2023-07-31 at 11.27.42 AM.png

This integration uses two variables:

  1. retryCounter: Integer variable to keep track of attempt number
  2. responseCode: Integer variable which would have status code of last execution of rest caller task.

Other variables are optional.

This integration would work as follows:

  1. Integration uses a While Loop task to call the sub integration based on following condition:
$retryCounter$ < 5 AND $responseCode$ >= 400
  1. Once the condition for the While Loop is evaluated to false (due to max attempts reached or success response code), we can continue with the integration based on the latest responseCode value.
  2. Use any tasks instead of Success Task or Failed Task based on your desired logic.

Resources

7 0 315
0 REPLIES 0