How to set request body of the nested list of data in HTTPoison multipart?

I have an post url parameters of format &room_details: [{id: 1, passangers: [{name: "hello"}]] . How to set this data in multi_part section.

I have tried something in payload as

payload = [{"room_details", Jason.encode!([%{id: 1, passangers: [%{name: "hello"}]])}]

and sending the request body as tuple {:multipart, payload}.


multipart/form-data and JSON usually aren’t used together in one request; can you describe the Content-Type and payload you’re looking for?

Example Request[{"numberOfChilds":"0","roomClassId":"{{room_class_unique_id}}","passangers":[{"salutation":"Mr","first_name":"john","last_name":"ankanna"}]},{"numberOfChilds":"0","roomClassId":"{{room_class_unique_id}}","passangers":[{"salutation":"Mr","first_name":"john","last_name":"ankanna"}]}]

It’s a method POST request.
How can I set the request body here. From post man those are query params.

I found one example of an API that looks just like this for, on a “code examples” site that scraped a now-deleted Github repo:

but it uses GET for action=hotel_reservation:

$params = array();
$params['section_unique_id'] = $SectionUniqueId;
$params['action'] = 'hotel_reservation';
$params['unique_id'] = $SearchUniqueId;
$params['hotel_id'] = $HotelId;
$params['agent_ref_no'] = 4444;
$params['roomDetails'] = '[{"numberOfChilds":1,"roomClassId":"' . $ClassUniqueId . '","passangers":[{"salutation":"Mr","first_name":"' . $_POST['name'] . '","last_name":"' . $_POST['family'] . '"}]}]';
$final = json_decode(get_Requestbody($params));
function get_Requestbody($param)
    $params = $param;
    $params['username'] = Public_Api_Username;
    $params['password'] = Public_Api_Password;
    $params['gzip'] = 'no';
    $url = Public_Api_URl;
    $str = '';
    foreach ($params as $index => $value) {
        $str .= $index . '=' . $value . '&';
    //remove last '&'
    $str = trim($str, "&");
    $url .= '?' . $str;
    $opts = array('http' => array('method' => "GET", 'header' => "Content-Type: text/html; charset=utf-8"));
    $context = stream_context_create($opts);
    $response = '';
    $c = 1;
    while (!$response && $c < 3) {
        $response = file_get_contents($url, false, $context);
        sleep($c + 3);
    return $response;

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.

Hi @al2o3cr Thanks for your time and effort.

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.

Curl Example

curl --location -g --request POST '{{hosst}}/ws/index.php?action=hotel_reservation&username={{usernaame}}&password={{passsword}}&unique_id=146028572&

Let me know if you need more information.

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?

Unfortunately I don’t have docs… @al2o3cr
Thanks for Everything.

Does this help?

# Define the list of data to include in the request body
data = [
    {:name, "John"},
    {:age, 35},
    {:email, ""},
    {:name, "Jane"},
    {:age, 32},
    {:email, ""},

# Use!/2 to send a POST request with the data
response =!(
    # 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...

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?