Not able to fetch all the records from source using restapi url #1426
-
I attempted to retrieve all of the records using restapi, but the default API url only returns 100 records. Is there a way to get all of the records from the source table? I tried query parameters such as?limit=200 & $offset=0, but nothing worked. Please see the attached image for more information. |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
A single GET response can contain a maximum of only 100 items. When an entity has more than 100 records, the JSON response will contain a field called Structure of the JSON response: {
"value": [...],
"nextLink": "..."
}
The |
Beta Was this translation helpful? Give feedback.
-
Pagination is done using the |
Beta Was this translation helpful? Give feedback.
-
Hi @severussundar/ @yorek - Thank you for responding so quickly! In the JSON response, I see "nextLink."in my data, But I'm not sure how I can use this "nextLink" to get the remaining records. I was able to fetch top n records using parameter $first=5. However, when I try to retrieve all of the records from the source using $first=100 & $after="nextLink". Or $first=100 & $after="xxxxxxx" getting an error. It would be great if you could provide an example of how to retrieve all data using rest APIs. |
Beta Was this translation helpful? Give feedback.
-
@Aniruddh25, @yorek - |
Beta Was this translation helpful? Give feedback.
-
@ma20114294 if you need to get all the items, you can first of all set the $first option to 10000, and then you just use the "nextLink" address to get the next 10000. Here's some code you can run in the browser console: async function loadItems(url) {
var items = [];
var fetchFrom = url;
while (fetchFrom != null) {
var response = await fetch(fetchFrom)
var payload = await response.json();
var result = payload.value;
result.forEach(item => items.push(item));
if (payload.nextLink) {
//console.log(`loading next item set: ${payload.nextLink}`)
fetchFrom = payload.nextLink;
} else {
fetchFrom = null
}
}
return items;
}
var items = await loadItems('https://localhost:5001/api/todo?$first=1000')
console.log(items.length); |
Beta Was this translation helpful? Give feedback.
Pagination is done using the
$first
and$after
parameters: https://github.com/Azure/data-api-builder/blob/main/docs/rest.md#first-and-after