I recommend you get a multipart request to your target endpoint working in Postman and post it here; that will help explain exactly what the API is expecting to see.
Here, I’m sharing working postman curl and postman Screenshot. I also tried encoding the url params with the help of URI.encode_query. But, that did not work either.
I still don’t understand your original question - both of the requests you’ve shown are using the POST method but passing all their parameters in the URL’s query string; there’s no multipart anything happening.
I’m also very skeptical that the API expects JSON in a parameter with \ mixed in.
Do you have a link to documentation for what you’re trying to call?
# Define the list of data to include in the request body
data = [
[
{:name, "John"},
{:age, 35},
{:email, "john@example.com"},
],
[
{:name, "Jane"},
{:age, 32},
{:email, "jane@example.com"},
],
]
# Use HTTPoison.post!/2 to send a POST request with the data
response = HTTPoison.post!(
"https://example.com/api/users",
data,
[
# Set the content type to multipart/form-data
{"Content-Type", "multipart/form-data"},
# Use the :multipart option to specify that the request body should be
# formatted as multipart/form-data
multipart: :multipart,
]
)
# Handle the response
case response.status_code do
200 ->
# If the request was successful, process the response data...
_ ->
# If the request failed, handle the error...
end
Thank for your time @sergio I will try this.
As per my understanding, I need to send list of objects and list of list right.
Correct me if I’m wrong. Treating each object as keyword list right?