-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdataverse_pagination.js
More file actions
34 lines (27 loc) · 847 Bytes
/
dataverse_pagination.js
File metadata and controls
34 lines (27 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const environmentUrl = "https://yourorg.crm.dynamics.com";
const accessToken = "YOUR_ACCESS_TOKEN";
const headers = {
Authorization: `Bearer ${accessToken}`,
Accept: "application/json",
"OData-Version": "4.0",
"OData-MaxVersion": "4.0",
};
let requestUrl = `${environmentUrl}/api/data/v9.2/accounts?$select=name,accountnumber`;
let pageNumber = 1;
async function run() {
while (requestUrl) {
const response = await fetch(requestUrl, { headers });
if (!response.ok) {
throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}
const payload = await response.json();
console.log(`Page ${pageNumber}`);
console.log(payload);
requestUrl = payload["@odata.nextLink"] || null;
pageNumber += 1;
}
}
run().catch((error) => {
console.error(error);
process.exitCode = 1;
});