Posting an array to Post/Put API with FromForm parameter

Currently I'm building a Form input which the values will be sent to a Post and Put API.
Now, the problem is, in the API, I have a couple dynamic array inputs.
It will be like this in Swagger:

Since the input is dynamic in quantity, I tried using using MultiSelect.

While the MultiSelect returns array, my API didn't recognize it as it is, only accept it as text

because rather than accepting it as an array, the system accept it as one text. *this one will accept the parse as array of guid:

Any idea on how to post it?

additional info, if I make the input becomes like this (idiot version)

it only accept the last input.

another update for above info:
I found up that I can do this:

but the problem now, is how can I make it dynamic? because the parameters quantity can be hundreds or 0

Found it!
I can use this

I'm back again, after some use, I found that the x-www-form-urlencoded can't be used for uploading file, while what I need is sending both the array and the file.
Anyone can help me?

Hi @DarkJoxie,

A lot of the specifics are going to depend on your specific API and what it was developed to accept. In cases where I need a more flexible body configuration than what's available with the different types, I've manually constructed a raw body with JS in other cases to get a format the API expects. It sounds like your API is looking for a multipart content type, and then the underlying chunks (separated by an arbitrary boundary you specify) are other content types.

Not the exact same but might get you started, here's an example of an API I was working with that was multipart and accepts a json object and a file in two different parts of the body. I just formatted it for readability using JS templating, and passed in values from components with the ${} syntax. Sounded like yours could use form-data instead of related like mine given your past attempts.


1 Like