How to use an api in filament
I have been trying to do is to use an external api with filament to list, view and edit.
What I have done is installing an api driver on my Laravel project and looked to integrate the api with my filament.
I tried to do it with a normal resource but i have no luck in making it work, I have also looked in the custom tables, forms and view docs but no luck.
I can't find the relevant docs to make it work.
Is it possible to use an api with filament?
note: i am rather new with external api's in Laravel and Filament.
20 Replies
Some people use the Sushi package to connect to external APIs, but I guess it's limited to a degree
yes, I all ready tried sushi to list the api, but it must do all the CRUD functions. And I haven't found any thing yet.π
Nothing simple / plug & play exists for this; one method would be to use sushi then override handleRecordUpdate, handleRecordCreation and override the delete action's (or create a seperate one).
A lot of the "magic" of Filament & Eloquent would be lost though, a more ideal solution would be to create some kind of sync service that syncs records between your own database and the API so you can interact with it properly.
like using an job to update my local DB?
Yeah essentially mirror the remote APIs structure in your own database, then when you want to handle edits/deletes you can dispatch jobs to a queue using an event listener to handle the API logic. This way Filament would work as though it was a regular model and you get instant updates while the API requests happen in the background
Option 1 of overriding the creation/update methods for the forms & using sushi for the table would be the easiest but you'll end up probably getting more and more frustrated when things don't work as smoothly as it would with a regular eloquent model.
Option 2 (the sync service route) would have the most seamless end user experience but be a fairly involved/advanced task for you
You can follow this tutorial https://laraveldaily.com/post/filament-load-table-data-from-3rd-party-api
Just as @Dennis Koch said are limited the features that you can use
You can try to create a API Wrapper and put the data coming from the external resource to internal models
Laravel Daily
Filament: Load Table Data From 3rd Party API
thank you
@Felix What kind of API are you speaking of? I have integrated multiple API's in my application, but I suppose it can depend on what you mean... Is it a Restful API?
I think it's an Restful API.
it's using an OAuth 2 authentication
I'm not sure how you want to CRUD an external API? That doesn't sound like something that should work out-of-the-box π
I know it is not easy, but it must be done one way or another.π
and the api that i am using has more or less CRUD functions for all its data.
Yeah it's possible you basically just need to write your own logic and can't use a lot of the nice features of filament
There is another api plugin in filament from husadana
Can you send me the link?
It's in the filament plugin website
I couldn't find it form husadana but did find some thing from Rupadana. are they the same ?
That plugin is just for conveniently registering api routes for an existing resource. Not for using an api as a resource
oke
FYI, I am now doing the "make my own local DB based of the API and fill the DB via an Get and Post via an job" method
not that it is the right solution
Ohh I see
Oh yes rupadana, my bad
no problem