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
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.
2
Sakthibalan
Thanks, @zachdaniel @kamaroly, It works good.
1
kamaroly
The following should also work.
actions do
# ========Add this line============
default_accept [:first_name, :last_name]
end
1
Popular in Questions
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
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
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
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
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
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
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
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
can someone please explain to me how Enum.reduce works with maps
New
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
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, how can I check the Phoenix version ?
Thanks !
New
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set?
Thanks.
New
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
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
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...
New
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
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
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
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








