Ash FrameworkAF
Ash Framework3y ago
20 replies
maxmannen

Can´t get json-api to work when passing arguments.

My api is working with no arguments but I can´t understand how to do it with passing arguments.
defmodule AshDatastore.Documents.Syllabus do

  use Ash.Resource,
  data_layer: Ash.DataLayer.Ets, extensions: [AshJsonApi.Resource]
  json_api do
    type "syllabus"
    routes do
      base "/syllabuses"
      get(:get_syllabus_documents, route: "/by_type/:country_code/:school_type/:document_type")
      index :read
    end
  end
  actions do
    defaults [:read, :create]
    code_interface do
      define_for AshDatastore.Documents
      define :get_syllabus_documents, args: [:country_code, :school_type, :document_type]
    end
    read :get_syllabus_documents do
      argument :country_code, :string
      argument :school_type, :string
      argument :document_type, :string
      filter expr(country_code== ^arg(:country_code) and school_type == ^arg(:school_type) and document_type==^arg(:document_type))
    end
  end

  attributes do
    uuid_primary_key :id
    attribute :country_code, :string
    attribute :school_type, :string
    attribute :document_type, :string
    attribute :content_map, :map
  end
end
I run this (with singel or dubbelbrackets- same result): http://localhost:4000/api/json/documents/syllabuses/by_type/"se"/"gy"/"courses" and get this: ``` { "errors": [ { "code": "NotFound", "detail": "No syllabus record found with country_code: "se", document_type: "courses", school_type: "gy"`",
"id": "1db6e507-92e1-4683-a133-517993305779",
"status": "404",
"title": "Entity Not Found"
}
],
"jsonapi": {
"version": "1.0"
}
}
```
Was this page helpful?