Skip to content

Commit 3512722

Browse files
authored
Merge pull request #148 from docusign/bugfix/fixes-for-monitor
Added the limits to the monitor example
2 parents a05aa73 + 1bfe225 commit 3512722

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

lib/monitor/examples/getMonitoringData.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @author DocuSign
55
*/
66

7-
const docusign = require('docusign-monitor');
7+
const docusign = require("docusign-monitor");
88

99
/**
1010
* This function does the work of getting the monitoring data
@@ -13,15 +13,41 @@ const getMonitoringData = async (args) => {
1313
//ds-snippet-start:Monitor1Step2
1414
let dsApiClient = new docusign.ApiClient();
1515
dsApiClient.setBasePath(args.basePath);
16-
dsApiClient.addDefaultHeader('Authorization', 'Bearer ' + args.accessToken);
16+
dsApiClient.addDefaultHeader("Authorization", "Bearer " + args.accessToken);
1717
//ds-snippet-end:Monitor1Step2
1818

1919
//ds-snippet-start:Monitor1Step3
20+
const limit = 100; // Amount of records you want to read in one request
21+
let functionResult = [];
22+
23+
let complete = false;
24+
let cursorValue, cursoredResult;
2025
const datasetApi = new docusign.DataSetApi(dsApiClient);
21-
const result = await datasetApi.getStream(args.version, args.dataset);
22-
//ds-snippet-end:Monitor1Step3
2326

24-
return result;
27+
let options = {
28+
limit: limit,
29+
};
30+
31+
// Get monitoring data
32+
do {
33+
if (cursorValue != null) {
34+
options.cursor = cursorValue;
35+
}
36+
cursoredResult = await datasetApi.getStream("2.0", "monitor", options);
37+
let endCursor = cursoredResult.endCursor;
38+
39+
// If the endCursor from the response is the same as the one that you already have,
40+
// it means that you have reached the end of the records
41+
if (endCursor === cursorValue) {
42+
complete = true;
43+
} else {
44+
cursorValue = endCursor;
45+
functionResult.push(cursoredResult.data);
46+
}
47+
} while (!complete);
48+
49+
//ds-snippet-end:Monitor1Step3
50+
return functionResult;
2551
};
2652

2753
module.exports = { getMonitoringData };

0 commit comments

Comments
 (0)