Please help me to convert curl request to tesla post request

here is the curl request: curl -v POST 'URL_OF_API' \ -H 'Accept: application/json' \ -H 'Authorization: Bearer TOKEN' \ -F 'listing={"products": [{"row": "DD","seat": "13","name": "1-61c171f5-4a96-4c5e-bf2c-07e965b0f9cc.pdf"}]}; type=application/json' \ -F '1-61c171f5-4a96-4c5e-bf2c-07e965b0f9cc.pdf=@1-61c171f5-4a96-4c5e-bf2c-07e965b0f9cc.pdf;type=application/pdf'

how i am converting it.
body:

%Tesla.Multipart{
  boundary: "983b569edcb39a5d0707fd9d00ad7931",
  content_type_params: [],
  parts: [
    %Tesla.Multipart.Part{
      body: "{\"products\":[{\"name\":\"1-61c171f5-4a96-4c5e-bf2c-07e965b0f9cc.pdf\",\"row\":\"DD\",\"seat\":\"13\"}]}",
      dispositions: [name: "listing"],
      headers: [{"content-type", "application/json"}]
    },
    %Tesla.Multipart.Part{
      body: %File.Stream{
        line_or_bytes: 2048,
        modes: [:raw, :read_ahead, :read, :binary],
        path: "priv/listing-files/listing-118755501/1-61c171f5-4a96-4c5e-bf2c-07e965b0f9cc.pdf",
        raw: true
      },
      dispositions: [
        name: "1-61c171f5-4a96-4c5e-bf2c-07e965b0f9cc.pdf",
        filename: "1-61c171f5-4a96-4c5e-bf2c-07e965b0f9cc.pdf"
      ],
      headers: [{"content-type", "application/pdf"}]
    }
  ]
}

client:

%Tesla.Client{
  adapter: nil,
  fun: nil,
  post: [],
  pre: [
    {Tesla.Middleware.BaseUrl, :call, ["BASE_URL"]},
    {Tesla.Middleware.Headers, :call,
     [
       [
         {"accept-language", "en-US"},
         {"authorization", "Bearer TOKEN"}
       ]
     ]},
    {Tesla.Middleware.JSON, :call, [[]]},
    {Tesla.Middleware.Telemetry, :call, [[]]},
    {Tesla.Middleware.Logger, :call, [[]]}
  ]
}

url: “/mobile/v3/1769384845”
opts: [adapter: [recv_timeout: 300000]]

Tesla.post(client, uri, body, opts: opts)

please tell me if I am missing something.

Well, there’s this site: https://curl.trillworks.com/

…but it only converts to HTTPoison. Still, it might be a good start for you, then you can try to translate from it to Tesla?

4 Likes