How to send a response that is different from the default one?

In my Ash resource, I’ve defined an action which returns a map like below:

actions do
  action :get_presigned_url, :map do
    run fn _, _ ->
      ...
      {:ok, %{filename: filename, presigned_url: presigned_url}}
    end
  end
end

But the above code returns an error saying that

an exception was raised:
    ** (Spark.Error.DslError) [MyApp.Domain]
json_api -> routes -> get -> get_presigned_url_for_audio:
  Invalid return type for generic action used in get route.

Expected type `:struct`
Expected constraints: instance_of: Dharana.Resource

Got type: Ash.Type.Map
Got constraints: []

Is it possible to do what I’m trying to do? I’m looking for a way to only send the map as the response through Ash

You can specify the return type of a generic action as the second argument. However, the error message feels wrong to me, as you don’t have a return type specified at the moment.

actions do
  action :get_presigned_url, :map do
    run fn _, _ ->
      ...
      {:ok, %{filename: filename, presigned_url: presigned_url}}
    end
  end
end

@barnabasJ Apologies! I did specify the return type in as a map in my actual code but forgot to mention it in the post. I’ve edited the original question now which includes the return type.

In that case you probably need to use route instead of get for a generic action

1 Like