Issue making multipart/form request with HTTPoison - Erlang error: {:badrecord, :dict}

I’m making the following request to Facebook.

Here’s the CURL

curl -X DELETE -F 'payload={
  "schema": [
    "EMAIL_SHA256"
  ],
  "data": [
    [
      "SOME_DATA",
    ]
  ]
}' -F 'access_token=SOME_TOKEN' https://graph.facebook.com/v6.0/act_SOME_ID/usersofanyaudience

I’m translating this to HTTPoison


url = "https://graph.facebook.com/v6.0/act_SOME_ID/usersofanyaudience"
form_data = {:multipart,
 [
   {"payload", "{\"schema\": [\"EMAIL_SHA256\"],\"data\": [[\"SOME_DATA\"]]}"},
   {"access_token", "SOME_TOKEN"}
 ]}
HTTPoison.delete(url, form_data)

When I run this I get the following error.


** (ErlangError) Erlang error: {:badrecord, :dict}
    (stdlib) dict.erl:413: :dict.get_slot/2
    (stdlib) dict.erl:91: :dict.is_key/2
    (hackney) deps/hackney/src/hackney_headers_new.erl:94: :hackney_headers_new.store_new/3
    (hackney) deps/hackney/src/hackney.erl:569: :hackney.host_header/2
    (hackney) deps/hackney/src/hackney.erl:605: :hackney.make_request/6
    (hackney) deps/hackney/src/hackney.erl:340: :hackney.request/5
    (httpoison) lib/httpoison/base.ex:796: HTTPoison.Base.request/6

Am I translating this CURL to HTTPoison wrong? Is my formatting wrong?

1 Like

You are passing your form_data as the headers parameter, perhaps you can pass it as the options parameter (third one), though that has to be a list as well.

Perhaps the following call will suceed:

HTTPoison.delete(url, [], [form_data])

If that does not work, you’ll need to build the request manually using HTTPoison.request/5.