Using API HTTP Request

I’m using UiPath 2024.10.4

I’m trying to use API HTTP Request to call a presigned url, attaching a file as a bytearray.
I’ve seen this post

but I’m wondering if this is still the case? Or is there any other way than to use Invoke code to pull this off?

HTTP Request activity is powerful enough to have covered all the scenarios I’ve faced since developing with UiPath Studio. I am not saying that you won’t ever need to code an API request with Invoke Code, but at least I haven’t yet required

Can you provide more information on the request you need to setup? If possible documentation, curl, or postman example so we can assist you

The issue I’m encountering is when it comes to uploading the bytearray. When I try to use parameters or attachments it complains it needs a string and cannot do byte array.

I was able to get it to work by doing Invoke code like the last post said.

string boundary = DateTime.Now.Ticks.ToString("x");
string LoanDocumentIdentifier = api_Object.SelectToken("LoanDocumentIdentifier")?.ToString() ?? "";
string url = api_Object.SelectToken("url")?.ToString() ?? "";
string fieldKey = api_Object.SelectToken("fields.key")?.ToString() ?? "";
string fieldXamzAlgorithm = api_Object.SelectToken("fields.x-amz-algorithm")?.ToString() ?? "";
string fieldXamzCredential = api_Object.SelectToken("fields.x-amz-credential")?.ToString() ?? "";
string fieldXamzDate = api_Object.SelectToken("fields.x-amz-date")?.ToString() ?? "";
string fieldXamzSecurityToken = api_Object.SelectToken("fields.x-amz-security-token")?.ToString() ?? "";
string fieldPolicy = api_Object.SelectToken("fields.policy")?.ToString() ?? "";
string fieldXamzSignature = api_Object.SelectToken("fields.x-amz-signature")?.ToString() ?? "";

  try	
  {	 
	using (var client = new System.Net.Http.HttpClient())
	{
		var request = new HttpRequestMessage(HttpMethod.Post, new Uri(url));
		var content = new MultipartFormDataContent(boundary);

		content.Add(new StringContent(fieldKey), "key");
		content.Add(new StringContent(fieldXamzAlgorithm), "x-amz-algorithm");
		content.Add(new StringContent(fieldXamzCredential), "x-amz-credential");
		content.Add(new StringContent(fieldXamzDate), "x-amz-date");
		content.Add(new StringContent(fieldXamzSecurityToken), "x-amz-security-token");
		content.Add(new StringContent(fieldPolicy), "policy");
		content.Add(new StringContent(fieldXamzSignature), "x-amz-signature");
		content.Add(new ByteArrayContent(in_pdf_byte_array), "file");

		request.Content = content;

		HttpResponseMessage response = client.PostAsync(url, content).Result;
		response.EnsureSuccessStatusCode();
		out_status_code = response.Content.ReadAsStringAsync().Result;
	}
  }
  catch(HttpRequestException e)
  {
	  out_status_code = e.Message;
  }

I just wasn’t able to get it working with UiPath API HTTP Request. This is something you’re able to help me with?

Multipart form data uploads can also be handled with HTTP Request activity

Values in Parameters section

And file in attachments

This is a working example of an upload to Alfresco Content Manager
https://docs.alfresco.com/content-services/6.0/develop/rest-api-guide/folders-files/#uploadfile

Hope it helps as reference

@Jennings_Michael welcome to the forum!

i dont need to use invoke code anymore
Now theres a “file attachments” property in http request activity

this property requires a List(ILocalResource) variable
what you do is
a. use path exist activity, pass in your filepath , then it will output a “iLocalResource” variable
b. declare a List(ILocalResource) variable, and use append item to list activity to add the variable from (a) to this list
c. finally you can pass this list to HTTP request activity note that body format should be application/x-www-form-urlencoded