srikanthkyatham

srikanthkyatham

Hi

I hope I am rephrase my usecase. I have trimmed down for clarity sake. Let’s say that, I have a

defmodule ResourceA do
  ...
  attributes do
    attribute :date
  end
end

ResourceB

defmodule ResourceB do
  ...
  attributes do
    attribute :methods, one_of: [:phone, :online]
  end
end

ResourceC - whose job is get values from ResourceA and ResourceB and return it.

defmodule ResourceC do
  ...
  code_interface do
    define :overlap, args:[...]
  end
  actions do
    action :overlaps, .. do
      argument :start_date, :string, allow_nil?: false
      argument :method, :atom, allow_nil?: false
      run fn input, context -> 
          start_date = inputs.arguments.start_date
          method = inputs.arguments.method
          # gets overlaps from ResourceA and ResourceB
          {:ok, result}
      end
    end
  end
end

Now in the Doamin

defmodule Domain do
use  Ash.Domain, extensions:[AshJsonApi.Domain]

resources do
 ...
end

json_api do
  routes do
   base_route "/overlaps", ResourceC do 
     route :get, "/overlaps", :overlaps
   end
  end
end
end

I am able to make the call. I can’t pass query params to the api call. I tried to debug but in vain. I am getting 400 error response. Any help is appreciated.

Thanks.

Showing Posts 1 to 7

zachdaniel

zachdaniel

Creator of Ash

In the code that I can see here, the action does not have start_date or method arguments. Have you added those arguments to the generic action?

zachdaniel

zachdaniel

Creator of Ash

Also, when sharing errors etc. please share as much context, like what the response body was for the 400 error and if there are any logs indicating additional detail etc. Just 400 status could be many many things :slight_smile:

srikanthkyatham

srikanthkyatham OP

Hi

My bad. Yes the start_date and method are arguments for the action.
here is the response.

15:52:27.017 [error] required: Required | is required


  1) test GET /get_slots (ResourceCTest)
     test/xxxx/api/reserve/resources/resourcec_test.exs:27
     Expected to get status 200 but got 400.

     Response body: %{
       "errors" => [
         %{
           "code" => "required",
           "detail" => "is required",
           "id" => "8745f55a-8645-4d96-a35d-2ea152158dfe",
           "meta" => %{},
           "status" => "400",
           "title" => "Required"
         }
       ],
       "jsonapi" => %{"version" => "1.0"}
     }

 code: ApiTestHelper.get_test(new_path, user, org_id, [])
     stacktrace:
       (ash_json_api 1.4.16) lib/ash_json_api/test/test.ex:68: AshJsonApi.Test.get/3
       (xxx 2.0.0) test/support/api_test_helper.ex:12: ApiTestHelper.get_test/4
       test/xxx/api/reserve/resources/resourcec.exs:81: (test)

I have noticed that if I don’t pass the arguments as query parameters. I get the error saying that I am missing the arguments. If I pass the arguments they are not ending up in the Ash.run_action() call being made from the GenericActionRoute. I am not sure what I was missing.

zachdaniel

zachdaniel

Creator of Ash

Hmm…it sounds like a bug? So input.arguments is an empty map?

srikanthkyatham

srikanthkyatham OP

Yes it is empty. I have noticed query_params is being populated in AshJsonApi.Request.parse_query_params, but it is relying on request.route. Not from request.query_params. I did not understand why it was done like that. I didnot dig deeper after that.

zachdaniel

zachdaniel

Creator of Ash

Oh, right, did you set this? AshJsonApi.Resource — ash_json_api v1.7.0

i.e query_params: [:start_date, :method]. I’m trying to remember why we require that to be set :thinking:… I think it is for post and other methods that could include a body and so require being told what is where. In the future we could probably assume that for get requests all of the inputs are query params.

srikanthkyatham

srikanthkyatham OP

Oh I missed that. I got it working. Thanks stupid me. I should have gone through the options first :disappointed:

— All posts loaded —

Where Next? Top

Trending in Discussions Top

cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
achempion
I’ve been using Emacs as my main code editor for more than a two years. It’s a custom build version although I’ve tried doom emacs and sp...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
georgeguimaraes
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews