Processing a JSON Document in a Backend Workflow

Hi there,

I’m pretty new to Bubble and I’ve already spent a lot of time figuring out this: I want to automatically save JSON-data from an API-Call to my bubble-database.
My Json-Data looks something like this:

{“TotalHits”:9048,“Documents”:[{“Title”:“Example Title”, “Url”:“http://forum.bubble.io/”, “Date”:“2022-09-26T18:55:08.8350000Z”}, {“Title”:“Example Title2”, “Url”:“http://forum.bubble.io/”, “Date”:“2022-08-26T18:55:08.8350000Z”}]}

I’m interested in each entry of the Documents (Title, Url and Date for each Document)
My API-Call is named GetDocsOnLoad and is set to Data.
I’ve created a new Datatype with a field “Documents” with the suggested type “GetDocsOnLoad Documents”:

My Backend-Workflow looks like this:

Then, in this backend-workflow, I want to “Create a new Thing” in order to fill my DocData-Table:


But here’s the issue: how can I achive to save the whole JSON to my database?
As you can see, it is always displayed in red, and nothing seems to help.
I’ve already tried to make an extra field in my “DocData” for each attribute of the JSON-File (Title, Url, Date) or to mark this field as a list, but none of this worked.

So my question is: how can I process and save the whole JSON file to my Database?

Thanks in Advance :slight_smile:

First question is why to save it as text? (if you want to save it as file or text, change your API Call to “text” or “file” type. You will be able to save it as text or file depending of the field you want to use)
But I’m not sure why you want to save it like that in your DB and how you will use it. So now sure this is the best option

What I think is that you want to save the Data of the JSON (not the json itself) into field of your DB.
The first thing to know is that, when you set API Call to be “Data” type, Bubble will create a “Thing” of the API Call type. You can save this in a field that have the type of API Call directly

IF you need for any reason, save each json object into a different field, you can process the API Call in backend WF and save it in DB by selecting the value you need. Like API Call’s TotalHit’s to a number field.

Thank you, this definitely makes sense…
So I want to run this workflow every night automatically.
I know that I have to kick this workflow off initially in the frontend and recall the same workflow in the workflow itself.
Therefore, I want to “Get Data From an External API” which should call my GetDocsOnLoad-Method.
But here, I cannot manage to make it work (unlike in the frontend where i can display the data on demand in the data source).

Frontend:

Backend (not working):

What is the problem?
Is it better to make an Action-API Call in a previous step and take this result as a source?

Which kind of field is TechBlog? Actually, the GetDocsOnLoadDocuments is the API type… the field need to be the same type. But you cannot set the Type of a field in Backend WF to an API Type (if I remember correctly). But anyway, you don’t really need to do that because your backend WF will call the API again to get fresh data (so why to send old data to backend WF?)
And why do you need to call it every night? What will you do with data?

Sorry, I renamed it - TechBlog was my Key “Document” in backend_load. As you suggested, I changed the Type of Key “TechBlog” from “text” to “DocData”.

I want to call it every night because I want to build a kind of dashboard with news which should be updated every day.

So my Workflow I want to achieve would be

  1. Initially start the Backend-Workflow via a Button in the Frontend
  2. Delete every old entry from my “DocData” in my Database
  3. Make a new API-Call to get the new data
  4. Save the new data to my data base (and display it)
  5. Repeat this workflow from step 2 every day

Is the payload very large?
If not, the best is to use 1 item and store the Whole result of api call in 1 field (of the type of the API Call)
If the payload is too large, you may need to search topic about recursive WF and API. There’s a lot of example