elixirdev
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.
Most Liked
dimitarvp
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
Popular in Questions
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
What is the idiomatic way of matching for not nil in Elixir?
E.g.,
First way:
defp halt_if_not_signed_in(conn, signed_in_account) when...
New
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Hey guys.
I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Mix format works fine if run from the cmd. I’ve followed this to facilitate the implementation into VSC which involves downloading an ext...
New
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum.
...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
Hi everyone!
I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Other popular topics
Hi! May someone helps me, please!
I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode.
The solution seems to be, in a hyphena...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
As a follow up to my earlier question:
I have the code compiling and running but not getting a successful login from the rest server. ...
New
Hi,
I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
Hello everybody,
usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New







