Skip to content

Commit

Permalink
Added paginated traversing through content items in capture.js script. (
Browse files Browse the repository at this point in the history
  • Loading branch information
azaslonov authored Nov 3, 2020
1 parent 8802cf5 commit 34af914
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions scripts.v2/capture.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,21 @@ async function getContentTypes() {
}

async function getContentItems(contentType) {
const data = await request("GET", `https://${managementApiEndpoint}/subscriptions/00000/resourceGroups/00000/providers/Microsoft.ApiManagement/service/00000/contentTypes/${contentType}/contentItems?api-version=2019-12-01`, managementApiAccessToken);
const contentItems = data.value;
const contentItems = [];
let nextPageUrl = `https://${managementApiEndpoint}/subscriptions/00000/resourceGroups/00000/providers/Microsoft.ApiManagement/service/00000/contentTypes/${contentType}/contentItems?api-version=2019-12-01`;

do {
const data = await request("GET", nextPageUrl, managementApiAccessToken);
contentItems.push(...data.value);

if (data.value.length > 0 && data.nextLink) {
nextPageUrl = data.nextLink;
}
else {
nextPageUrl = null;
}
}
while (nextPageUrl)

return contentItems;
}
Expand Down

0 comments on commit 34af914

Please sign in to comment.