Create list of things from API - I'm stuck :(

Hi Everyone! @romanmg

I am trying to create a list of things from my external API. The API is returning the correct values, but I am getting all the values returned into a single thing as opposed to each value returned into a new row.

Here is my API setup:

Here is what is saving to the database:

I would like it to save like this:

Here is my API/workflows:



Any help here would be greatly appreciated!!

Thank you,
Kyle

5 Likes

I’m not familiar with the All Sports API and I’m not sure I totally follow your data structure, but I assume you want to set the Away, Home and ID fields not the Away list, Home list and ID list fields as you’ve shown. If this is correct then try this …

  1. In your api endpoint “add schedule”, add three parameters, let’s call them pAway, pHome and pID, setting their data types as appropriate. I expect they are all text fields.

  2. In the Create a new Schedule step of this workflow, set Away = pAway; Home = pHome and ID = pID.

  3. In your When Button A is clicked workflow, I would suggest deleting the first step and when scheduling your API Workflow on a list, set the Type to All Sports API …json’s results, or whatever it is called. Then set the parameters for your end point like pAway = This All Sports API …json’s AwayTeam; pHome = This All Sports API …json’s HomeTeam and pID = This All Sports API …json’s ID.

If you’re still stuck, you may want to make your app public and share a link, which should it make it easier for people to help.

Edit: I found this old thread that may help - Need help writing to database with list called from api source

8 Likes

THANK YOU!! Worked perfectly. Your older post really helped too.

1 Like

Happy to help.

That’s how it works. Welcome to what I call the “API Ghetto” data type. It’s a hassle. There’s little more to say about it. These objects (the list elements) are neither searchable nor saveable. But they exist on the database if you store them there.

It is — without doubt — the stupidest thing in @bubble right now. Bubble please fix.

1 Like

Total mobile misfire on my previous attempt to reply with more info… apologies.

Meant to say: Here is my original (and still relevant) explication of this Issue:

1 Like

@keith Are you recommending that data returned from API calls should automatically be saved to the database because currently you can always save through API workflows and search lists etc

1 Like

Hi @neerja,

That’s not what I’m suggesting. What I am suggesting is that, when one receives a response that is a list of a compound data type, that one have the option of having Bubble create that data type in the database so that such objects, when saved, can actually be accessed.

I feel like I’ve explained this a bunch of times in different ways. The problem goes like this:

  1. You have an API call “My API Call” that returns a list of compound data (a JSON structure). For example, an array of Events where each Event in the list (for example) has a start_date, end_date, and note.

  2. The API Connector sees this list and retrieves it. This list becomes a data blob object that Bubble calls “My Api Call Events”. It is a list of Events and Bubble knows this once the API call is Initialized. It knows what an Event is and knows what a list of Events looks like.

  3. We can take this data blob and attach it to some object. We do that by going into the Data tab and adding a field on some object to receive a list of that type. Here’s a real world example: I have an API that I built myself that returns a list of Events. The API call is called “iCalFromURL” and so this phantom data type (I don’t know what you call it internally – an API data type, perhaps?) becomes “iCalFromURL Event”.

In the data tab, I can now create fields of that type. Below the list of types that we have defined in our database, we find a list of API Connector-defined data types. “iCalFromURL Event” will be one of these. Here it is:

So I can make a receptacle to contain this list on some object. In my case, I put a field on my “Calendar” data type that a list of iCalFromURL Events:

  1. Now we may have a workflow that Gets Data from API and retrieves this list via the “iCalFromURL” API call and stores it on a Calendar object.

  2. Now that we have this, we can do things like visualize that list in a Repeating Group (for example). If Some_Calendar is an object of Calendar type, the source for such a repeating group could be “Some_Calendar’s iCal Events”.

  3. However, this is the ONLY way to retrieve an “iCalFromURL Event” from the database. The only “handle” we have to this blob of iCal Events is via that field on Calendar objects. In Bubble terms, an “iCalFromURL Event” is neither saveable nor searchable. It is a primitive, like the integer 2. Each of these objects exists and is stored in the Bubble database, but they do not have a unique ID I guess (at least, not one that is exposed to us).

  4. This is exceedingly strange because Bubble knows all about an “iCalFromURL Event”. In the hypothetical RG I mention above (which contains a List of iCal Events), we can show each iCal Event’s start_date, end_date, note, etc., and other fields that it has.

  5. But we cannot search for these in the database. Neither can we modify them. Neither can we create a new iCal Event. This seems to be purely because we have no way of promoting the “iCal Event” data type up to the main database level. It resides in what I call “the API Ghetto”.

We can only operate on these (and in a very limited way) by downloading the full blob to the browser and then using list operations on them there. Once we have that list we can do all of the usual things, like select the _n_th iCal Event in the list. (e.g., Calendar’s iCal Events:item 4 – this expression resolves to a single object of iCalFromURL Event type)

We can similarly use client-side functions like :filter on this list to narrow it down.

But this object is not a Thing. We cannot make changes to it as there’s no way to select a Thing of that type. Such objects are not found in the list of Things in our app. But they exist and they are there in the database. Similarly, we cannot Create a New Thing of this type.

All we can do is grab an existing object of this type and do stuff like push it on to another list of that type.

  1. I might be totally wrong about this, but it seems like we shouldn’t have to iterate over a list like this and individually Create a New Thing of some parallel data type to get access to them. Why can we not just ask Bubble to “promote” the iCalFromURL Event data type to a Custom Data Type so that we can now select this data type as a search / create / make changes target?
16 Likes

@keith Thanks for the detailed breakdown. Our engineering team will review.

3 Likes

Thank you, was really helpfull.

1 Like

wow after searching for hours, I finally found someone with my exact same problem :slight_smile:
I managed to get it working with trial and errors.
It’s very unintuitive the way it works

Thanks for the help

2 Likes

what if I can’t save data in database, because it’s sensitive, but I have same issue when instead of glossary :, API’s JSON gives me a single string of keys and values ?
12312312
report quickbooks

Where is the solution you found?

this topic is the answer
follow the screenshots and voilĂ 

You need to schedule an api workflow on a list and schedule it to run and change the item saved each time until the number of items saved = the number of items in the api call

Having a custom plugin to accomplish this is a more efficient process. You can send the entire api list to the plugin and in a server side action api calls can be made at a much faster rate to save this data.

You could also make bulk api calls in the editor or a plugin.

Learn more

Need to have your database located in your region! Tired of struggling with Bubble or API’s? Need a little functionality that’s not available yet thru current market plugins? Experience your own bootcamp!

Are you ready to step-it-up or speed it along? Need some custom code or a plugin built? Contact me today to learn how to book a 1-on-1 session, get your plugin built, or yet freelance building support!

Office Hours:
Mon - Fri
9:00 AM - 5:00 PM

Send me a message today:
Jared@KnowCodeConsultants.com

1 Like

Were you able to figure this out?

I am facing same issues

Decided to store data in Bubble database, created a parser on the backend creating separate row per a metric. It was possible, because API was giving a string like {“Metric Name AAA”," Value AAA",“Metric Name BBB”,“Value BBB”,“Metric Name CCC”,“Value CCC”}

1 Like