alxvallejo

alxvallejo

Hey all,

I’m trying to make a GET request while passing in body params. One param requires a list of strings. The API documentation states:

curl -s --user 'api:YOUR_API_KEY' -G \
   https://api.mailgun.net/v3/YOUR_DOMAIN_NAME/stats/total \
   -d event='accepted' \
   -d event='delivered' \
   -d event='failed' \
   -d duration='1m'

In Elixir, here is how I’m preparing the body:

    body =
      %{event: ["accepted"]}
      |> Plug.Conn.Query.encode

However the response I get is:

    ** (Bamboo.ApiError) There was a problem sending the email through the Mailgun API.

Here is the response:

"{\"message\":\"please provide at least one event: Missing mandatory parameter: event\"}\n"

Here are the params we sent:

"event[]=accepted"

Any ideas on what i’m doing wrong here?

Showing Posts 1 to 3

chulkilee

chulkilee

First, that curl is not using body. See -G option - it uses data under -d as query parameter.

If you use -v option in curl - you can see the data are in the query string - ?event=accepted&event=delivered&event=failed&duration=1m

Okay - so you just need to build the query parameter then. You can use URI.encode_query/1.

URI.encode_query([event: "accepted", event: "delivered", event: "failed", duration: "1m"])
# => "event=accepted&event=delivered&event=failed&duration=1m"

Note

  • keywords allows duplicate keys
  • URI.encode_query/1 accepts atom

I really like the design of Elixir standard lib here - query parameter should not be implemented as map (as duplicate key is possible) and the order is preserved (as in keywords), and no magic transformation (e.g. passing list as value) . I saw many “easy to use” http interface are based on wrong assumption on many details…

dimitarvp

dimitarvp

What kind of list? Comma-separated? Or a JSON-style list?

If the latter, your parameter can be encoded like so:

...?event[]=1&event[]=2&event[]=3

A lot of framework backends – Plug (and thus Phoenix) included – will decode the above as event=[1,2,3].

sb8244

sb8244

Author of Real-Time Phoenix

Can you include the code that calls out to Mailgun? I see the query preparation, but not how that is actually being sent along. My initial guess is that maybe that part is not setup correctly.

Do you mean query params? GET requests technically can have a body, but I would put the chances of a service respecting it very low.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews