Hello UiPath Community,
I am encountering an issue with the HTTP Request activity in UiPath Studio. I have a variable that I’m trying to use to set the RequestBodyFormat property, but it seems to be treated as a string literal instead of recognizing it as a variable.
Here’s what I’ve done so far:
I have a String variable named myRequestBodyFormat that holds the MIME type for the HTTP request body (e.g., “application/json”).
I’m attempting to set the RequestBodyFormat property of the HTTP Request activity using this variable.
In the Properties panel, I set RequestBodyFormat to myRequestBodyFormat (without quotes).
Despite these steps, the activity does not seem to acknowledge the variable as such and is treating it as a literal string. Here’s an example of how I’m setting it:
myRequestBodyFormat = "application/json" ' I've verified this value is correct
I’ve made sure that the variable is in scope and correctly initialized before reaching this activity. However, the request is not behaving as expected, as if the format is not being set properly.
Could someone please help me understand why the variable is not being treated correctly in the HTTP Request activity’s RequestBodyFormat property? Is there a specific syntax or step I am missing?
Thank you for your assistance!
Unfortunately, this is a limitation of this input property:
It does not allow for dynamic values.
You can, however, work around this by setting your own header value, key: Content-Type, value: your variable. It should normally overwrite the Body Format input property and you should be good to go.
I will take it as an improvement request for the future redesign of this activity.
Hi @loginerror , The solution which you provided worked fine, Thanks a lot for the quick reply.
One follow-up question, the Header Collection in the API Request Activity, We need to add the header one by one statically the key name, is there a way to pass the Header Collection Array as a variable dynamically?
You can use the custom activity or VB script to call this API, first, you need to test API in postman, then you have to go to left side your postman and select the language and export, you can export this any language and use in your code
Indeed, the solution mentioned above is the only one in case the headers need to be provided as a variable.
The way to do it with code would be to either use the Invoke Code activity, or the Coded Workflow feature (starting with Studio 2023.10). The latter is much easier to work with.