Converting API Response JSON into a temp object?

I am calling a 3rd Party API and retrieving a list of objects. I want these objects to be suggestions where the user then picks the one they want to use and this suggested object is what gets stored into my database.

However, I don’t want to store every suggestion in my database to be able to display it and show it as an object in my UI.

How can I do this? Is there any way to create an object from the API response that lives on the page and not stored in my database?

Hi, in the API connector use your call as a “Data” not “Action”.
Then you have the choice:

  • Directly call your api in a Repeating Group Data source
  • Set a state with the list of temporary objects from the api call on page load

In both case you can choose in your RG or your state the Data Type of your call.
E.g. your call is “GET Objects Suggestions”, then you can choose the data type “GET Objects Suggestions” in the data type dropdown.

Hope this help

Awesome thank you!

So that’s one piece of the puzzle, but the second piece trying to get it to appear properly to match my database object (Thing) without saving it – hopefully I can try and reuse a component for it. But I also have a variable amount of data and I’d want to loop over the keys in the JSON without using another plugin.

How can I take the raw data and create a “temp” thing without committing it to my database?

Hi, I need more infos at this point.
Can you share a screenshot of your API result and the data type in which you try to fit this data pls?
And maybe also give an example for the variable amount of data and the loop you need to do?

If the JSON you are receiving is an array, bubble can identify the object and you can extract any of the field of the “GET Objects Suggestions” data type to populate elements in a Repeating Group for example.
Look of an array:

"items": [
   {"name": "Suggestion 1"
    ...
   },
   {"name": "Suggestion 2"
    ...
   },
   ...
]

In some case, the JSON is not an array but a list of independant objects. Then bubble can’t manipulate it correctly. Then there is a quick work around to remap it so you can use it without saving any data in the database.
Look of a list of objects:

{
   "item1": {
       "name": "Suggestion 1"
        ...
       },
   "item2": {
       "name": "Suggestion 2"
        ...
       },
   ...
}