Hi there!
I’m trying to build a kind of dashboard which displays news retrieved from an external API.
This already works fine on page-load (on demand), but since I don’t want to make a new API-Call every time somebody opens this page, I want to schedule this API-Call.
Therefore, I need to store the retrieved data in the bubble-database.
The data consits of JSON-Files with several attributes.
In my API-Call, I chose the option “Data” instead of “Action”.
Which steps are necessary to resolve this problem?
Do I need to use a recurring event?
You can just schedule a backend workflow to run every 24 hours (say, at midnight)…
And set the relevant data in your database to the API call data.
Then you can use that datatype data from the DB on your page instead of making the API call every time the page is loaded.
Thank you for your fast reply, but these steps are actually the problem I cannot solve.
- Where exactly can I set my backend workflow to run every 24 hours?
- Where and how can I set the relevant data to the API call data?
Just create a recursive backend workflow…
i.e. set up a backend workflow to set the database data to the API data, and add an action to schedule itself for midnight the next day (i.e. current date/time: +(days) 1: rounded down to Day, or you can just use Current date/time: +(days) 1)
You’ll need to kick it off initially from the front-end, so you can just create a temporary admin page with a button to start the workflow, and schedule it to run at midnight (or whatever time you want it to run)
- Where and how can I set the relevant data to the API call data?
Assuming you’ve got a datatype to store the data, with a field set to the type of the API call (and if you haven’t then you’ll need to create one), just use a make changes to thing workflow action to set the data in the relevant datatype…
You’ll need to create it first - so you could add a create a thing action to the initial workflow that kicks it off to create the thing in the database initially…
Alternatively, you might want to store each day’s API data separately for historical record sake, in which case use the workflow to create a new thing each day and set the API field to the data from the API call.
Thank you, your tip to initially start the backend workflow with a button event was very helpful!
So as I’m trying to create a datatype to store the data, I got the problem that my JSON-file from the API-Call looks like this:
{“TotalHits”:9048,“Documents”:[{“Title”:“Example Title”, “Date”:“2022-09-26T18:55:08.8350000Z”}, {“Title”:“Example Title2”, “Date”:“2022-08-26T18:55:08.8350000Z”}]}
I just want to save the entries for each Document (Title and Date).
When I’m trying to create a new field for my new datatype, I can only choose “GetAPIresult Document”, but I can not choose “GetAPIresult Document Title” and so on.
So is this field a list of things?
How can I set the parameters of the backend workflow correctly in this case?
Can’t you just save the full response?
Why do you need to save each field separately - you can refer to those in your data sources on the page…
Hi @adamhholmes,
Can you share this steps in brief with bubble options for how we can store external API data into bubble database table when page is loaded?