Saving API result to DB?

My API returns a a list with a nested list. There is a list of subject data type (Subject body subject) that contains a list of case date type (Subject case) . I want to save the content into DB.

In the backend, both data types are not available in API WF. Without them I can’t do recursive loop. Why is that?

In the front end, I can have access to the 2 data types, but I can’t pass them to the backend to do the looping so the subject can be created before the subject is available when creating the cases.

Any idea how I can save the a nested list to DB?



1 Like

Hi,

I think that you need create a new data table .

You will choose this table in Data Types list (image bellow). It’s not a Basic Type

image

I have created something like this, but I still don’t know how to I can loop through the subject list and then loop through the case list to save the data into a Bubble data type.

Have you done something like this? @dualpixel

1
2

1 Like

After searching on the forum with “nested JSON to database”, it seems that it is not possible in Bubble. I need to flattern the JSON with javascripg/plugin/external service.

In some cases, it would be sufficient to store the whole object in a field of one data type (so there is no need for looping), and then access its nested lists from the frontend and display their content

1 Like

Displaying nested list to RG is not a problem. However, I need to save the individual data to the DB, so I need to do recursive workflow where the API data type is not available on the API WF.

Hi,

I think this video will help you. Take a look at it

Yes, I saw this. However, this video only process a list with 1 level, while I have a list of item with a nested list inside the item.

Trying to do exactly the same in there… Save API call with Lists

Have you been able to find some clues please ?

I did not find anything. So I asked the dev who created the API to return a flattened list.

I think it is possible to get the result as text and then use a custom plugin to parse the result into a proper list with sublists. Maybe.

1 Like

Ok thank you

Handling multi level JSON responses in bubble is a nightmare.
All I can think of is if there is a 2 level of grouping of responses you can launch a loop. In 3 level you would need to launch a loop in a loop which maybe very costly.

My current go-to solution is to do level 2 in a loop within a loop. Agree about the potential WU cost of level 3 but you should probably also consider limits, of some kind. For example, in my BE WF loops I use Counter and Max to loop, and stop loops. I also have an ‘and’ with a hard limit on the Max variable.

counter < max and max < 250

(for example - to ensure there’s a hard limit somewhere). |

I also store level 2 json into Supabase if I need it, I’ll call that json back on demand (if that demand ever surfaces).

1 Like

One possible option is to write a JS code in Bubble with the Toolbox plugin and parse the data and return a flatten list.