Pagination
Page through large collections such as builds and diffs using Argos's page-based pagination.
Last updated
Was this helpful?
Was this helpful?
curl "https://api.argos-ci.com/v2/projects/my-team/my-project/builds?page=2&perPage=50" \
-H "Authorization: Bearer $ARGOS_TOKEN"const url = new URL(
"https://api.argos-ci.com/v2/projects/my-team/my-project/builds",
);
url.searchParams.set("page", "2");
url.searchParams.set("perPage", "50");
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.ARGOS_TOKEN}` },
});
const { pageInfo, results } = await response.json();async function fetchAllBuilds(owner, project) {
const perPage = 100;
let page = 1;
const builds = [];
while (true) {
const url = new URL(
`https://api.argos-ci.com/v2/projects/${owner}/${project}/builds`,
);
url.searchParams.set("page", String(page));
url.searchParams.set("perPage", String(perPage));
const response = await fetch(url, {
headers: { Authorization: `Bearer ${process.env.ARGOS_TOKEN}` },
});
const { pageInfo, results } = await response.json();
builds.push(...results);
if (page * pageInfo.perPage >= pageInfo.total) {
break;
}
page += 1;
}
return builds;
}