I want to make a request in the api data postman using cursor and limit, but it always only returns 50 rows. how to increase the amount of data returned?
do you have more than 50 entries in the DB? If so, I’m curious if Bubble has limited this based on plan type.
Your use of limit of 2000 should get you 2000 rows of data if Bubble does not have a limit on the limit.
A bit of information for anyone using the Data API and running into this post (like me)…
Directly in a browser tab, you can use this format:
https://paul-testing-4.bubbleapps.io/version-test/api/1.1/obj/vectors?key=namespace&constraint_type=equals&value=default&cursor=10&limit=3
Using a fetch request with JavaScript (client-side), you can use:
(removing the cursor and limit will return all records, max 100)
fetch('https://paul-testing-4.bubbleapps.io/version-test/api/1.1/obj/vectors?key=namespace&constraint_type=equals&value=default&cursor=10&limit=40', {
method: 'GET',
}).then((response) => {
return response.json();
}).then((data) => {
console.log(data);
});
Using the “remaining” value in the response to get all the data, then this will work:
let allRecords = [];
let allResults = [];
let limit = 100;
fetch(`https://paul-testing-4.bubbleapps.io/version-test/api/1.1/obj/vectors?key=namespace&constraint_type=equals&value=default&limit=${limit}`, {
method: 'GET'
}).then((response) => {
return response.json();
}).then((data) => {
allRecords = allRecords.concat(data.response);
let remaining = data.response.remaining;
let pages = Math.ceil(remaining / limit);
let fetchRemainingRecords = async () => {
for (let i = 0; i < pages; i++) {
let cursor = limit * (i + 1);
let response = await fetch(`https://paul-testing-4.bubbleapps.io/version-test/api/1.1/obj/vectors?key=namespace&constraint_type=equals&value=default&cursor=${cursor}&limit=${limit}`, {
method: 'GET'
});
let data = await response.json();
allRecords = allRecords.concat(data.response);
}
allResults = allRecords.flatMap(obj => obj.results);
console.log(allResults);
};
fetchRemainingRecords();
}).catch((err) => {
reject(err);
});
does that javascript basically loop through making multiple calls until all records have been fetched before it returns the response with everything that was fetched combined into a single response?
It does yes. I use it within one of my plugins, then store the data in a global variable to cache for subsequent uses of the data. I don’t have to keep calling it then whenever I need to use it.