1
votes

I'm new to Elixir 1.3.2 and Phoenix 1.2.1 and i'm trying to post a user object(map) to phoenix after following this tutorial. I'm using postman and the correct url http://localhost:4000/api/users. At first i tried a raw body with a json object but then i got a missing key exception: expected key "user" to be present in params, please send the expected key or adapt your scrub_params/2 call

Then i used the formdata option in postman with a key:"User" and value:"{email: "[email protected]", password: "s3cr3t"}". This resulted in the following error response from the elixir API: expected params to be a map, got: "{email: \"[email protected]\", password: \"s3cr3t\"}"

Can anyone tell me what i'm doing wrong? And how you would make sure JSON gets serialized/matched to a map?

1

1 Answers

0
votes

The JSON that you need to send to the server needs to look something like

{
  "user": {
    "email": "[email protected]",
    ...
  }
}

Note how there is a user key at the top level. That is what your error meant by

expected key "user" to be present in params