F
Filament8mo ago
AgonK

how to send request and get response inside action button

Im trying to send get/post request inside action ( button in header section). I tried with route and Http::post(route(name,params) but nothing works. How can I send request and get response, and based on response show the notification
Solution:
yes I checked with debug never go to my endponit, however I do not need this because I will use directly to my service cointainer instead of endpoint
Jump to solution
16 Replies
Anik
Anik8mo ago
provide code
AgonK
AgonKOP8mo ago
I excepted to do something like this Action::make('generate_invoices') ->label(('filament.generate_monthly_invoice')) ->icon('heroicon-o-document-duplicate') ->tooltip(('filament.generate_monthly_invoice')) ->action(function (){ $response = route('generate-monthly-invoices', ['title'=>'Auto generate']); }), or ->action(function (){ $response = Http::get(route('generate-monthly-invoices', ['title'=>'Auto generate'])); }), but nothing works @Anik
Anik
Anik8mo ago
are you using it inside forms?
AgonK
AgonKOP8mo ago
no, only button inside my resource I don't need any form, I will only generate in my API route and send response to this action only for generating notification @Anik
Anik
Anik8mo ago
try
action($this->anyThing())

public function anything() {
// logic here
}
action($this->anyThing())

public function anything() {
// logic here
}
Dennis Koch
Dennis Koch8mo ago
but nothing works
You need to explain "nothing works" a bit more
AgonK
AgonKOP8mo ago
yes Dennis, nothing work. I don't have any response only click the button and nothing happend there is no error
Dennis Koch
Dennis Koch8mo ago
What are you doing with the "response" after receiving it?
AgonK
AgonKOP8mo ago
I want to use to send notification, but the response is only route as a string generate-monthly-invoices/title=Auto generate I excpect the response to by my api response
Dennis Koch
Dennis Koch8mo ago
For the first example you only generate a route. But it should for the second example
AgonK
AgonKOP8mo ago
okay but how its the right way to use my existing API using actions
Dennis Koch
Dennis Koch8mo ago
What's the issue with the second solution? Not sure why you'd do HTTP calls inside your own application instead of calling the code directly, but it should work
AgonK
AgonKOP8mo ago
yes you are right, I also call service function instead API route The error of second solution is cURL error 28: Operation timed out after 30005 milliseconds with 0 bytes received (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://127.0.0.1:8000/api/invoices/monthly?title=AutoGenerate
Dennis Koch
Dennis Koch8mo ago
The error is pretty clear isn’t it? Your request takes longer than 30 seconds and is timed out by the client.
Solution
AgonK
AgonK8mo ago
yes I checked with debug never go to my endponit, however I do not need this because I will use directly to my service cointainer instead of endpoint
AgonK
AgonKOP8mo ago
thank you for you help and remind me xD

Did you find this page helpful?