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
2753module . exports = { getMonitoringData } ;
0 commit comments