Custom payload body for post endpoint
How can create a generic action so that the exposed endpoint would accept the following payload:
I tried the following:
but I'm getting this error when I try to submit:
12 Replies
How are you setting up the route?
If you are using
post ...
then it will attempt to make it an idiomatic JSON:API
route
Use route/3
for fully custom logic
and see the generated open api spec/swagger docs for what shape the API expects.This is how I defined the route in the domain
Take a look at
route
https://hexdocs.pm/ash_json_api/dsl-ashjsonapi-resource.html#json_api-routes-routeIt improved a bit, but it is still wrapping everything in a data object
the only change I made was to replace the
post :create
block I posted above by route :post, "/path", :create
Hmm...are you sure its not
{"result": {....}}
?
Its actually data.data
?
oh, nvm result objects default to false
.
right, its probably because of the way that it serializes it
What if you just do
?
Its been a bit since I've been in that code, sorry 😄Nah, I'm still seing the arguments wrapped in the data object

I wonder if it is not easier to just write a regular phoenix controller to call the ash domain in this case. Given it is for a webhook I have no control over
Yep, you definitely can. And also, sorry, I didn't realize you were talking about the arguments, not the output
Solution
But yeah TBH for webhooks I typically just write controllers
AshJsonApi was designed to help build
JSON:API
compliant APIs
i.e for serving public APIs and/or building applications etc.makes total sense. And thanks for helping me navigating through my newbie questions.
My pleasure 🙇♂️