Forum Academy Marketplace Showcase Pricing Features

How to populate dropdown with results from API

Hi,

New to Bubble. I’m trying to populate a dropdown using results collected from an API. Ideally the value of the option would be the returned “id” field, and the option text would be “name”. Data returned from the API is JSON format.

Fwiw, I can use the returned results to create a new “thing”, but can’t get it to work as a dropdown selection.

Each user can have multiple locations. Not sure if there is a better way to do this?

Returned JSON looks like this:

[

{
“zip”: 91711,
“image”: “”,
“city”: “Claremont”,
“typename”: “SINGLE FAMILY HOME”,
“typeid”: 1,
“address”: “111 1st Ave”,
“userid”: 6,
“state”: “CA”,
“id”: 41,
“lotsize”: 0,
“name”: “TEST”
}
]

Any help is greatly appreciated.

Could you share a link to your editor?

Not sure this is how you do it, but here you go: https://bubble.io/page?type=page&name=index&id=testyw&tab=tabs-1

Hm, trying to understand this API call. Is it supposed to return multiple values because it looks like it’s only returning 1…?

You’re right though, for whatever reason, it’s not coming up as an API option as a data source. I’m not sure if there’s something that I’m missing due to that specific API or if it’s a bug.

I’ve just added a 2nd entry into the db, so the api returns 2 records (though in my mind it really should be able to work with just 1 entry).

New response looks like this:

[
   {
      "zip": 91711,
      "image": "",
      "city": "Claremont",
      "typename": "SINGLE FAMILY HOME",
      "typeid": 1,
      "address": "111 1st St",
      "userid": 6,
      "state": "CA",
      "id": 41,
      "lotsize": 0,
      "name": "TEST"
   },
   {
      "zip": 91702,
      "image": "",
      "city": "Azusa",
      "typename": "APARTMENT COMPLEX",
      "typeid": 2,
      "address": "222 2nd Ave",
      "userid": 6,
      "state": "CA",
      "id": 42,
      "lotsize": 0,
      "name": "2ND Test"
   }
]

Holy cow - just got it to work. I had the api call set to action instead of data. I was loading the data from the API on page load, when I really don’t have to do that. Just call it from the element itself.

Thanks so much for your help!

Ah, yes! Great! That’s why I thought it was weird it wasn’t coming up as a data option. Totally overlooked that. Glad you caught it! :slight_smile: