@@ -15,7 +15,19 @@ const createBulkExportRequest = async (args) => {
1515
1616 //ds-snippet-start:Admin3Step3
1717 const bulkExportsApi = new docusignAdmin . BulkExportsApi ( apiClient ) ;
18- let exportResponse = await bulkExportsApi . createUserListExport ( requestBody , args . organizationId ) ;
18+ let exportResponse = await bulkExportsApi . createUserListExport ( requestBody , args . organizationId , ( error , data , response ) => {
19+ const headers = response ?. headers ;
20+
21+ const remaining = headers ?. [ 'x-ratelimit-remaining' ] ;
22+ const reset = headers ?. [ 'x-ratelimit-reset' ] ;
23+
24+ if ( remaining && reset ) {
25+ const resetInstant = new Date ( Number ( reset ) * 1000 ) ;
26+
27+ console . log ( `API calls remaining: ${ remaining } ` ) ;
28+ console . log ( `Next Reset: ${ resetInstant . toISOString ( ) } ` ) ;
29+ }
30+ } ) ;
1931 //ds-snippet-end:Admin3Step3
2032
2133 const sleep = ( ms ) => {
@@ -26,11 +38,23 @@ const createBulkExportRequest = async (args) => {
2638
2739 const getExportedUserData = async ( exportId ) => {
2840 //ds-snippet-start:Admin3Step4
29- const bulkExportResponse = await bulkExportsApi . getUserListExport ( args . organizationId , exportId ) ;
41+ const bulkExportResponse = await bulkExportsApi . getUserListExport ( args . organizationId , exportId , ( error , data , response ) => {
42+ const headers = response ?. headers ;
43+
44+ const remaining = headers ?. [ 'x-ratelimit-remaining' ] ;
45+ const reset = headers ?. [ 'x-ratelimit-reset' ] ;
46+
47+ if ( remaining && reset ) {
48+ const resetInstant = new Date ( Number ( reset ) * 1000 ) ;
49+
50+ console . log ( `API calls remaining: ${ remaining } ` ) ;
51+ console . log ( `Next Reset: ${ resetInstant . toISOString ( ) } ` ) ;
52+ }
53+ } ) ;
3054 //ds-snippet-end:Admin3Step4
3155
3256 //ds-snippet-start:Admin3Step5
33- const dataUrl = bulkExportResponse . results [ 0 ] . url ;
57+ const dataUrl = bulkExportResponse . data . results [ 0 ] . url ;
3458 const requestOptions = {
3559 method : 'GET' ,
3660 headers : {
@@ -60,17 +84,29 @@ const createBulkExportRequest = async (args) => {
6084 let retryCount = 10 ;
6185
6286 while ( retryCount >= 0 ) {
63- if ( exportResponse . status === 'completed' ) {
64- await getExportedUserData ( exportResponse . id ) ;
87+ if ( exportResponse . data . status === 'completed' ) {
88+ await getExportedUserData ( exportResponse . data . id ) ;
6589 break ;
6690 } else {
6791 -- retryCount ;
6892 await sleep ( 5000 ) ;
69- exportResponse = await bulkExportsApi . getUserListExport ( args . organizationId , exportResponse . id ) ;
93+ exportResponse = await bulkExportsApi . getUserListExport ( args . organizationId , exportResponse . data . id , ( error , data , response ) => {
94+ const headers = response ?. headers ;
95+
96+ const remaining = headers ?. [ 'x-ratelimit-remaining' ] ;
97+ const reset = headers ?. [ 'x-ratelimit-reset' ] ;
98+
99+ if ( remaining && reset ) {
100+ const resetInstant = new Date ( Number ( reset ) * 1000 ) ;
101+
102+ console . log ( `API calls remaining: ${ remaining } ` ) ;
103+ console . log ( `Next Reset: ${ resetInstant . toISOString ( ) } ` ) ;
104+ }
105+ } ) ;
70106 }
71107 }
72108
73- return exportResponse ;
109+ return exportResponse . data ;
74110} ;
75111
76112module . exports = { createBulkExportRequest } ;
0 commit comments