99import com .docusign .esign .model .*;
1010
1111import java .io .IOException ;
12+ import java .time .Instant ;
1213import java .util .Collections ;
1314import java .util .List ;
15+ import java .util .Map ;
1416import java .util .concurrent .TimeUnit ;
1517
1618public final class BulkSendEnvelopesService {
@@ -35,7 +37,17 @@ public static BulkSendBatchStatus getBulkSendBatchStatus(
3537 ) throws ApiException , InterruptedException {
3638 TimeUnit .SECONDS .sleep (bulkRequestDelay );
3739 // For 2000 recipients, it can take about an hour
38- return bulkEnvelopesApi .getBulkSendBatchStatus (accountId , batchId );
40+ var getBulkSendBatchStatus = bulkEnvelopesApi .getBulkSendBatchStatusWithHttpInfo (accountId , batchId );
41+ Map <String , List <String >> headers = getBulkSendBatchStatus .getHeaders ();
42+ java .util .List <String > remaining = headers .get ("X-RateLimit-Remaining" );
43+ List <String > reset = headers .get ("X-RateLimit-Reset" );
44+
45+ if (remaining != null & reset != null & !remaining .isEmpty () & !reset .isEmpty ()) {
46+ Instant resetInstant = Instant .ofEpochSecond (Long .parseLong (reset .get (0 )));
47+ System .out .println ("API calls remaining: " + remaining );
48+ System .out .println ("Next Reset: " + resetInstant );
49+ }
50+ return getBulkSendBatchStatus .getData ();
3951 }
4052 //ds-snippet-end:eSign31Step7
4153
@@ -63,25 +75,65 @@ public static String bulkSendEnvelopes(
6375 ccEmail2
6476 );
6577
66- String bulkListId = bulkEnvelopesApi .createBulkSendList (accountId , sendingList ).getListId ();
78+ var bulkListResponse = bulkEnvelopesApi .createBulkSendListWithHttpInfo (accountId , sendingList );
79+ Map <String , List <String >> headers = bulkListResponse .getHeaders ();
80+ java .util .List <String > remaining = headers .get ("X-RateLimit-Remaining" );
81+ List <String > reset = headers .get ("X-RateLimit-Reset" );
82+
83+ if (remaining != null & reset != null & !remaining .isEmpty () & !reset .isEmpty ()) {
84+ Instant resetInstant = Instant .ofEpochSecond (Long .parseLong (reset .get (0 )));
85+ System .out .println ("API calls remaining: " + remaining );
86+ System .out .println ("Next Reset: " + resetInstant );
87+ }
88+ String bulkListId =bulkListResponse .getData ().getListId ();
6789
6890 // Create an envelope
6991 //ds-snippet-start:eSign31Step4
7092 EnvelopesApi envelopesApi = new EnvelopesApi (apiClient );
71- String envelopeId = envelopesApi .createEnvelope (accountId , makeEnvelope ()).getEnvelopeId ();
93+ var envelopeResponse = envelopesApi .createEnvelopeWithHttpInfo (accountId , makeEnvelope (), envelopesApi .new CreateEnvelopeOptions ());
94+ headers = envelopeResponse .getHeaders ();
95+ remaining = headers .get ("X-RateLimit-Remaining" );
96+ reset = headers .get ("X-RateLimit-Reset" );
97+
98+ if (remaining != null & reset != null & !remaining .isEmpty () & !reset .isEmpty ()) {
99+ Instant resetInstant = Instant .ofEpochSecond (Long .parseLong (reset .get (0 )));
100+ System .out .println ("API calls remaining: " + remaining );
101+ System .out .println ("Next Reset: " + resetInstant );
102+ }
103+ String envelopeId = envelopeResponse .getData ().getEnvelopeId ();
72104 //ds-snippet-end:eSign31Step4
73105
74106 // Attach your bulk list ID to the envelope
75107 //ds-snippet-start:eSign31Step5
76108 CustomFields customFields = createCustomFields (bulkListId );
77- envelopesApi .createCustomFields (accountId , envelopeId , customFields );
109+ var createCustomFields = envelopesApi .createCustomFieldsWithHttpInfo (accountId , envelopeId , customFields );
110+ headers = createCustomFields .getHeaders ();
111+ remaining = headers .get ("X-RateLimit-Remaining" );
112+ reset = headers .get ("X-RateLimit-Reset" );
113+
114+ if (remaining != null & reset != null & !remaining .isEmpty () & !reset .isEmpty ()) {
115+ Instant resetInstant = Instant .ofEpochSecond (Long .parseLong (reset .get (0 )));
116+ System .out .println ("API calls remaining: " + remaining );
117+ System .out .println ("Next Reset: " + resetInstant );
118+ }
78119 //ds-snippet-end:eSign31Step5
79120
80121 // Initiate bulk send
81122 //ds-snippet-start:eSign31Step6
82123 BulkSendRequest request = new BulkSendRequest ();
83124 request .setEnvelopeOrTemplateId (envelopeId );
84- return bulkEnvelopesApi .createBulkSendRequest (accountId , bulkListId , request ).getBatchId ();
125+
126+ var bulkSendResponse = bulkEnvelopesApi .createBulkSendRequestWithHttpInfo (accountId , bulkListId , request );
127+ headers = createCustomFields .getHeaders ();
128+ remaining = headers .get ("X-RateLimit-Remaining" );
129+ reset = headers .get ("X-RateLimit-Reset" );
130+
131+ if (remaining != null & reset != null & !remaining .isEmpty () & !reset .isEmpty ()) {
132+ Instant resetInstant = Instant .ofEpochSecond (Long .parseLong (reset .get (0 )));
133+ System .out .println ("API calls remaining: " + remaining );
134+ System .out .println ("Next Reset: " + resetInstant );
135+ }
136+ return bulkSendResponse .getData ().getBatchId ();
85137 //ds-snippet-end:eSign31Step6
86138 }
87139
0 commit comments