HTTP Request (UipPath.Web.Activities.HttpClient) with more than one attachment for Freshdesk API

Hey there,

I try to make a POST request towards our Freshdesk instance with more than one file attachment.
Freshdesk guidelines for attachments are these.

So the request needs to be in “multipart/form-data”, this sample code (found here) should show the usage of multiple attachments:

curl -v -u yourapikey:X -F "attachments[]=@/path/to/attachment1.ext" -F "attachments[]=@/path/to/attachment2.ext" -F "email=example@example.com" -F "subject=Ticket Title" -F "description=this is a sample ticket" -X POST 'https://domain.freshdesk.com/api/v2/tickets'

So it needs to be different filenames, BUT the same form/field name “attachments”.

When I look at the options, the HTTP request activity gives me, I see two for attachments:
image
So either via the collection or via direct input of a vb.net expression.

I am successfully using the first for sending only one attachment:
image

But I am struggling, with giving the activity more than one attachment, as I do need to give the same name:

Is there an option to use the second property “File attachments” to solve my issue?
If so, how to convert this array of filenames into this ICollection of ILocalResource?
image

Looking forward to you help.

Best,
Thomas

Hi @thomas.huemer

Did you try changing the input type in arguments and pass an array of files instead?

cheers

Hello @Anil_G,

I suppose you are talking about the second options, so “File attachments”.

Of which type needs the array to be?
I tried with array of fileinfo or a list of this array. Both get conversion errors:
image

Recheck the different TypeArguments:
grafik

Here a dictionary is needed. the inArguments we can create e.g with:
new InArgument(Of String)(“C:\Test\abc.txt”). but will be done for us when we fill out argument wizard

File Attachments:
grafik

In newer versions files are represented by ILocalResource which is derived e.g. to FileSystemLocalItem

For second unfortunately we cannot create manually and do need it to get returned e.g. File Exists - returning it for a single file

As a workaround we can do:

Hi @ppr,

thanks a lot for that help - So I now was able to add the files via collection.
But somehow, as expected, Freshdesk responded with an error:

Result: False / Message: Error when sending Email - Message: {“description”:“Validation failed”,“errors”:[{“field”:“TestFile”,“message”:“Unexpected/invalid field in request”,“code”:“invalid_field”}]}

I guess, that is because the HTTP request activity names the attachments after the filename, where Freshdesk allows only the name “attachments”, as stated in my first post.

And going with the dictionary option would not be possible aswell, because dictionaries do not allow for two keys with the same name, as also posted earlier:

So is there any workaround which does not involve invoke code?
Or did I missunderstand anything?

your names are not unique. so it complains the duplicated argument name

I know, but exactly this is a prerequisite for the endpoint to accept the http request:
So all attachments, regardless of their name have to be called like this:

If I go for “attachment1” and “attachment2”, the api request would fail.

Hi @thomas.huemer

Sorry for late response. I hope ppr answered your bit

Can you try changing the name of attachments to be same as what you need and if you are attaching multiple files , then place them in different folders with same name. As arguments are having same name as filename this might suffice

cheers

That would be really much effort to resolve it, but it could work.
I’ll try and let you know.

Thank you @Anil_G

attachments[0]
attachments[1]
would maybe a more close name

But we would recommend to research more on the API docu and also ensure that other settings e.g. multipart/form-data is done properly.

Often we do a RnD middle round in Postman and then map back the setting to the HTTP Request.
Whenever we are blocked by HttpRequest activity we can do:

  • custom code invoke code
  • and customize the request with using RestSharp

Hey @ppr

thank you for your tip, I tried with calling them like you suggested.
image

This is what I got:
image

So recipient side crashed totally, not even being able to return any validation error.

I guess Freshdesk attachment logic and UiPath HTTP request activity are not compatible to each other :frowning:

@Anil_G → I tried your suggestion aswell. It works with one file, but it somehow corrupts the files, if you attach more than one.
And, with your suggestion, I would completely bin all the attachment names. Which I don’t really want.

So if there is no other idea, I maybe need to use invoke code :frowning:

1 Like

we don’t think so far. As mentioned:

once there is some cross check done and works ok, then we can check for some details.

Also have a look here:


created with the wizard. So internally it is added as Attachments to the request. we just configuren a name and a valid filepath

1 Like

Thank you ppr

Also have a look here:


created with the wizard. So internally it is added as Attachments to the request. we just configuren a name and a valid filepath

This will not work either.
In this example, both attachments do have the field names “CV” and “Letter” and Freshdesk will deny it.
As far as I know (and all my prior tests confirm that), all attachments have to be called “attachments”. You even need the squared brackets for all of them.

Just as in this example, I already posted:

If any attachment does not follow that rule, it will be denied.
I ask Freshdesk support, if there is any exception from that rule - Maybe they know a solution.

And I try to play around a bit with online API testing tools (local ones are no option, as we are not allowed to install any local one).

Hi @thomas.huemer

If you are looking for using invoke code then this might help you in building

Cheers

keep in mind, that internally these information will be used, post-processed and then added to the requestParameters

The name of the file is preserved after it is attached i.e the filename sent in the response will be the same as the one in the request.

yes, we have seen in their docu the curl part -F for multipart form data
in their C# example-(done for only 1 atttachment)
surprising are the same traces of question (sending multiple attachments / unique names…) when checking other resources e.g. the freshdesk forum…

Perfect as we would also recommend getting it done anyhow. Once it is confirmed that the API is working / controllable then we can do the mapping to a solution approach and also giving feedback to UiPath if there is a break within the functionalities.

For analyzing techniques also have a look here (using fiddler for request inspections) just for the idea even when the scenario was a different one

Short update on that.

I unfortunately got no reply from FD support yet to confirm how it works.
But I tried around a bit with the API and the only way it works, is to name all attachments the same.

So I decided to go for Invoke Code and came up with this working thingy:

  Dim client As System.Net.Http.HttpClient = New System.Net.Http.HttpClient()
  client.BaseAddress = New Uri(EndPoint)
  client.DefaultRequestHeaders.Accept.Clear()
  client.DefaultRequestHeaders.Accept.Add(New System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"))
  client.DefaultRequestHeaders.Authorization = New System.Net.Http.Headers.AuthenticationHeaderValue("Basic", auth)
  
  Dim request As System.Net.Http.MultipartFormDataContent = New System.Net.Http.MultipartFormDataContent("----------------------------" + DateTime.Now.Ticks.ToString("x"))
  request.Add(New System.Net.Http.StringContent(subject), """subject""")
  request.Add(New System.Net.Http.StringContent(email), """email""")
  request.Add(New System.Net.Http.StringContent(description), """description""")
  request.Add(New System.Net.Http.StringContent(email_config_id), """email_config_id""")
  request.Add(New System.Net.Http.StringContent("2"), """status""")
  request.Add(New System.Net.Http.StringContent("1"), """priority""")
  files.ForEach(Sub( f As String) request.Add(New System.Net.Http.StreamContent(System.IO.File.OpenRead(f)), "attachments[]", (New FileInfo(f).Name)))
    
  Dim response As System.Net.Http.HttpResponseMessage = client.PostAsync("", request).Result
  status = response.StatusCode
  result = response.Content.ReadAsStringAsync.Result

So I am happy with what I have now, but the question arises, if the activity should have some rework???

@ppr - Fiddler is not an option, as we are not allowed to install such tools by our IT policy (we also do not have admin rights on our laptops).

1 Like

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