How to Dynamically Set the HTTP Method in a Single HTTP Request Activity?

Hello UiPath Community,

I am working on an API testing automation project in UiPath Studio, and I have encountered a challenge. I need to dynamically set the HTTP method (GET, POST, PUT, DELETE, etc.) for an HTTP Request activity based on data read from a CSV file. Each row in the CSV file contains the API endpoint, headers, request body, and the HTTP method to be used for that particular API call.

I am looking for a way to configure the HTTP Request activity to use a single instance to send requests with different HTTP methods as specified in the CSV file without having to create separate activities for each HTTP method.

Here are the specifics of what I am trying to achieve:

  • Read data from a CSV file with columns for URL, Header, RequestBody, and RequestMethod.
  • For each row in the CSV file, extract the values and use them to make an API call with the specified request method.
  • Capture the response from the API call and store it back in the CSV.

I attempted to use a variable to set the Method property directly in the HTTP Request activity, but the activity does not allow binding a variable to this property. I am looking for an alternative solution that allows me to use a single HTTP Request activity to handle dynamic HTTP methods.

Could someone please guide me on how to achieve this, or provide an example of how to set the HTTP method dynamically for the HTTP Request activity in UiPath Studio?

Thank you for your help!

Hi!

I would suggest you use a switch or an else-if that checks your current RequestMethod and uses the appropriate method:

If you absolutely want to use the RequestMethod as an input to your HTTPRequest you would have to build your own using invoke code or coded workflow.

Okay Thanks for the solution, But I was looking into the way where I need to do less changes if there is some changes come, Here in the Switch or If Else Acitivty, I have to change each and every HTTP Activity, that I want to avoid.

I will wait for someone else to respond with that solution, If not, I will go ahead and use the solution which you described.

As an lternate you can check if a custom HTTPClient coding will better serves you need

However as there differences between the different HTTP Methods it is carefully to evaluate if a One-Thing-does-All is appropriate or not

Okay Thanks for the response, I will better use the Switch Activity only to write different HTTP Activity, So that it’s easier to manage.

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