Sakthibalan

Sakthibalan

Post request got an InvalidBody error

I created a post request (localhost:4000/api/students/)

Headers:
‘Accept: application/vnd.api+json’
‘Content-Type: application/vnd.api+json’

Body:

{
  "data": {
    "type": "student",
    "attributes": {
      "first_name": "some name",
      "last_name": "last name"
    }
  }
}

I got an error InvalidBody

{
    "errors": [
        {
            "code": "invalid_body",
            "id": "a174c29e-5ffe-4cf4-b4a4-97a67f6e65aa",
            "meta": {},
            "status": "400",
            "title": "InvalidBody",
            "source": {
                "pointer": "data/attributes/last_name"
            },
            "detail": "Expected only defined properties, got key [\"data\", \"attributes\", \"last_name\"]."
        },
        {
            "code": "invalid_body",
            "id": "a6408d19-4271-4753-b86a-134fd009af93",
            "meta": {},
            "status": "400",
            "title": "InvalidBody",
            "source": {
                "pointer": "data/attributes/first_name"
            },
            "detail": "Expected only defined properties, got key [\"data\", \"attributes\", \"first_name\"]."
        }
    ],
    "jsonapi": {
        "version": "1.0"
    }
}

Most Liked

zachdaniel

zachdaniel

Creator of Ash

Two things:

First, The reason for this specific error is that the first and last name are not accepted by the actions. You probably want:


create :create do
  accept [:first_name, :last_name]
end

update :update do
  accept [:first_name, :last_name]
end

second, you likely want to make the first and last name attributes public? so that they display in the API.

Sakthibalan

Sakthibalan

Thanks, @zachdaniel @kamaroly, It works good.

kamaroly

kamaroly

The following should also work.

  actions do
    # ========Add this line============
    default_accept  [:first_name, :last_name]
  end

Where Next?

Popular in Questions Top

vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
lanycrost
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
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New

Other popular topics Top

rms.mrcs
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
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New

We're in Beta

About us Mission Statement