F
Filamentβ€’9mo ago
Felix

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
Dennis Koch
Dennis Kochβ€’9mo ago
Some people use the Sushi package to connect to external APIs, but I guess it's limited to a degree
Felix
Felixβ€’9mo ago
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.πŸ˜•
ConnorHowell
ConnorHowellβ€’9mo ago
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.
Felix
Felixβ€’9mo ago
like using an job to update my local DB?
ConnorHowell
ConnorHowellβ€’9mo ago
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
jersonmr
jersonmrβ€’9mo ago
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
Felix
Felixβ€’9mo ago
thank you
Andrew Wallo
Andrew Walloβ€’9mo ago
@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?
Felix
Felixβ€’9mo ago
I think it's an Restful API. it's using an OAuth 2 authentication
alexanderkroneis
alexanderkroneisβ€’9mo ago
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 πŸ˜…
Felix
Felixβ€’9mo ago
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.
ConnorHowell
ConnorHowellβ€’9mo ago
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
einnlleinhatt_
einnlleinhatt_β€’9mo ago
There is another api plugin in filament from husadana
Felix
Felixβ€’9mo ago
Can you send me the link?
einnlleinhatt_
einnlleinhatt_β€’9mo ago
It's in the filament plugin website
Felix
Felixβ€’9mo ago
I couldn't find it form husadana but did find some thing from Rupadana. are they the same ?
ConnorHowell
ConnorHowellβ€’9mo ago
That plugin is just for conveniently registering api routes for an existing resource. Not for using an api as a resource
Felix
Felixβ€’9mo ago
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
einnlleinhatt_
einnlleinhatt_β€’9mo ago
Ohh I see Oh yes rupadana, my bad
Felix
Felixβ€’9mo ago
no problem
Want results from more Discord servers?
Add your server
More Posts