How to add JSON and file in multipart/form-data body to a POST API request?

Basically this works in Postman but can’t make it work in UiPath:

Similar to this: how-to-send-a-body-type-form-data-using-post-in-a-http-request. However, answer was for a file and string, not for JSON. I keep on getting this error in the response:

{
  "error": {
    "code": "NRC_INVALID_PARAM",
    "code_message": "Invalid parameter for request",
    "details": "No JSON object could be decoded",
    "message": "Invalid parameter for request"
  }
}

maybethe discussion below will help:

Hi @ticsrobo.au,

Have you tried writing the payload in a notepad file and then using it as a string input to the activity?

Thanks

From my point of view the code should be like this:

String varstr = JObject.FromObject(
   New With {
        key .name = "Jeff",
        key .id = 1,
        key .car = "BMW"
    }
).ToString

request.Add(New StringContent(“profile”), varstr)
request.Add(New StreamContent(File.OpenRead(“C:\8A.docx”)), “file”, (New FileInfo(“C:\8A.docx”).Name))

The logic is like this you build JSON separately and then you provide it as a string.
Here you have a movie with code on how to build JSON

Thanks,
Cristian