How to handle an array of objects

I’m new to Bubble, and try to connect to an API that return an array of objects directly like this:

[
  {
    "Code2": "GB",
    "Code3": "GBR",
    "RegionCode": "",
    "Culture": "GB",
    "Name": "United Kingdom",
    "Vat": 25
  },
  {
    "Code2": "NO",
    "Code3": "NOR",
    "RegionCode": "",
    "Culture": "no",
    "Name": "Norway"
  }
]

The API call is named GET All Countries but I do not get an option to say that this is a list of type Country the editor automatically set it to data type GET All Countrie as in single form, but it makes no sense.

How do I handle this. Could I format the response somehow and make it more like this from within Bubble:

{
  response: [
    {
      "Code2": "GB",
      "Code3": "GBR",
      "RegionCode": "",
      "Culture": "GB",
      "Name": "United Kingdom",
      "Vat": 25
    },
    {
      "Code2": "NO",
      "Code3": "NOR",
      "RegionCode": "",
      "Culture": "no",
      "Name": "Norway"
    }
  ]
}

Or how should I approach this response?

Comment 1
I can see that it is working. I do get the data, and can iterate on it. I suppose I just want the data type to be of type Country and not GET All Countrie. If there is any way to make this happen from within Bubble, I would be happy :slight_smile:

Yes, change the name of your API call in the API connector from GET All Countrie to Country and then reinitialize it

The API call is named GET All Countries and not GET All Countrie Bubble renames it automatically to GET All Countrie. And if I rename it to just Country that would not make sense, since I’m really fetching an array of countries.

Anyway it is working. Its just my OCD that hates the way it is being named I guess :stuck_out_tongue:

Ohh Sorry about that. I suggested the idea of naming it to country simply because you suggested that…not that it made sense to me, but just gave you the answer to the question you asked.


But @martin23 it is not correct that Bubble renames it automatically to GET All Countrie.

Yes, this may be true that the API provided labeled it as such, but in your Bubble app in the API connector plugin, you most likely named it GET All Countrie.

An example below to demonstrate for other users how things actually work in Bubble.

In Stripe, Stripe will label the API call as List all invoices

In my app, in the API connector, for that API call, in the name field, I named it Get all invoices that have ever existed in the world

Now, Bubble does not automatically rename that for me

Screen Shot 2024-03-17 at 9.50.13 PM

Screen Shot 2024-03-17 at 9.50.25 PM

If you look close enough, you can see, the name of the API call is exactly as I named it in the API connector and the name of the data type is exactly the same as the name of the API call.

Bubble does not automatically change the name of API calls…the only areas that they automatically change the name is to pluralize (which is opposite of taking Countries and changing it to Countrie) so that something that reads color may become colors, so in your situation, Bubble definitely didn’t change it from countries to countrie; I believe what happened in your situation is you named the API call GET All Countrie

So, if you want to fix the situation for the sake of your OCD, you can do as I explained in my original answer, but maybe instead of using your first suggestion of making the data type be of type Country, you instead label the API call Get All Countries

Hope this helps clear up any confusion you had.

And BTW, if I am incorrect and Bubble is changing the name automatically, that is a bug and you should submit a bug report.