Data API records Python

Hi!
I am trying to use a get request to treat my data out of bubble, using python.
The problem is it is always showing only 100 records, even if I set a higher limit.
Does anyone know how to show all data?
Thanks !!

1 Like

It is a defacto best practice across the web to paginate the return of large datasets. As stated in the Bubble documentation Workflow APIs have a return limit. Likewise Data APIs are automatically paginated. Your choice is to either build a manual pagination Workflow API, or structure your database so that a Data API can return the paginated results.

Hi,

This is the expected behavior :slightly_smiling_face:
The max value of limit is 100. So Bubble will never return more than 100 objects per API call.

To get all the objects using the Data API, you have to call it several times.

For example:

  1. Call the data API with limit = 100

  2. Get the number of remaining objects - response[“remaining”]

  3. Compute the number of remaining pages

    nb_pages = ceil(remaining / limit)

  4. Loop to get all the objects

    for i in range(nb_pages):
       cursor = limit * (i + 1)
       # then you use the cursor parameter on the GET request
    
3 Likes

The above worked well for me, my final code looks like:

results = []

url = "[Data API root URL]"

myHeaders = {

    'Authorization':'Bearer [Your API Key]',

    'Content-type':'application/json'

}
response = requests.get(url, headers = myHeaders).json()

raw = response['response']['results']

left = response['response']['remaining']

pages = round(left/100) #should probably use ceil() here but didn't wanna import math

for i in raw:

  results.append(i)

cursor = 100*(i+1)

params={'count':100,

        'cursor':cursor}

response=requests.get(url, headers=myHeaders,params=params).json()

raw=response['response']['results']

for i in raw:

  results.append(i)

df = pd.DataFrame(results)
1 Like