Best practices for HTTP Request API Call

Can any one share some point on UiPath HTTP Request activities best practices?

1 Like

Hi @mubarakhusain235

Welcome to UiPath Community. I will share some of the best practices we follow while handling the HTTP requests.

  1. This is more of a generic one. No Hardcoded values. Ex: End Point, Parameters, and Headers.
  2. HTTP request is wrapped inside the Retry Scope activity. under Action part HTTP Request activity is placed and under condition part, Is False is placed. The reason is when there is an error for an HTTP request we have to validate it through the status code only unlike UiElements this activity will not throw any error.
    The approach would be to capture the status code from HTTP Request activity and use the below condition to validate (This is one of the validation we are performing)
not(TokenResultCode.ToString.Equals("401") Or TokenResultCode.ToString.Equals("403") Or TokenResultCode.ToString.StartsWith("2"))

The above expression is used in the Is False condition and below is the explanation
If the status starts with 2 then it is a successful scenario so no need to retry
If the status is either 401 or 403 then it is something related to authorization and authentication and we don’t retry in this scenario as there is a risk of password lock if there are multiple invalid attempts. The above status code you can modify the expression based on how your API is designed but the one I mentioned works for most of the cases.

so apart from these three scenarios if there is any other status code bot will retry as per the number we provided.
3. Have a good clarity on your response part. Whether it would be Json or XML. If it’s a successful scenario then it’s fine you would deserialize JSON as per your process. Even after multiple retries if your API call is not successful then log the error after deserializing the JSON response for better debugging purposes. Proper exception handling while deserializing is also something to look for.

YourJSONObject("error").ToString

This sums up pretty much everything we follow in our process which are running smoothly in production. Please let me know if you need any further details on the points I specified above.

Thank you.

2 Likes

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