1+ from datetime import datetime as dt , timezone
12from docusign_admin import ApiClient , ProductPermissionProfilesApi , DSGroupsApi , UsersApi , NewMultiProductUserAddRequest , ProductPermissionProfileRequest , DSGroupRequest
23from flask import session , json , request
34
@@ -37,7 +38,19 @@ def get_permission_profiles(args):
3738 )
3839 #ds-snippet-start:Admin2Step3
3940 product_permission_profiles_api = ProductPermissionProfilesApi (api_client = api_client )
40- profiles = product_permission_profiles_api .get_product_permission_profiles (organization_id = org_id , account_id = session ["ds_account_id" ])
41+ (profiles , status , headers ) = product_permission_profiles_api .get_product_permission_profiles_with_http_info (
42+ organization_id = org_id ,
43+ account_id = session ["ds_account_id" ]
44+ )
45+
46+ remaining = headers .get ("X-RateLimit-Remaining" )
47+ reset = headers .get ("X-RateLimit-Reset" )
48+
49+ if remaining is not None and reset is not None :
50+ reset_date = dt .fromtimestamp (int (reset ), tz = timezone .utc )
51+ print (f"API calls remaining: { remaining } " )
52+ print (f"Next Reset: { reset_date } " )
53+
4154 profiles_list = profiles .to_dict ()["product_permission_profiles" ]
4255 #ds-snippet-end:Admin2Step3
4356 return profiles_list
@@ -59,8 +72,20 @@ def get_groups(args):
5972
6073 #ds-snippet-start:Admin2Step4
6174 ds_groups_api = DSGroupsApi (api_client )
62- ds_groups = ds_groups_api .get_ds_groups (organization_id = org_id , account_id = session ["ds_account_id" ])
75+ (ds_groups , status , headers ) = ds_groups_api .get_ds_groups_with_http_info (
76+ organization_id = org_id ,
77+ account_id = session ["ds_account_id" ]
78+ )
79+
80+ remaining = headers .get ("X-RateLimit-Remaining" )
81+ reset = headers .get ("X-RateLimit-Reset" )
82+
83+ if remaining is not None and reset is not None :
84+ reset_date = dt .fromtimestamp (int (reset ), tz = timezone .utc )
85+ print (f"API calls remaining: { remaining } " )
86+ print (f"Next Reset: { reset_date } " )
6387 #ds-snippet-end:Admin2Step4
88+
6489 return ds_groups
6590
6691 @staticmethod
@@ -108,7 +133,19 @@ def worker(self, args):
108133
109134 #ds-snippet-start:Admin2Step6
110135 users_api = UsersApi (api_client )
111- response = users_api .add_or_update_user (organization_id = org_id , account_id = session ["ds_account_id" ], request = new_user )
136+ (response , status , headers ) = users_api .add_or_update_user_with_http_info (
137+ organization_id = org_id ,
138+ account_id = session ["ds_account_id" ],
139+ request = new_user
140+ )
141+
142+ remaining = headers .get ("X-RateLimit-Remaining" )
143+ reset = headers .get ("X-RateLimit-Reset" )
144+
145+ if remaining is not None and reset is not None :
146+ reset_date = dt .fromtimestamp (int (reset ), tz = timezone .utc )
147+ print (f"API calls remaining: { remaining } " )
148+ print (f"Next Reset: { reset_date } " )
112149 #ds-snippet-end:Admin2Step6
113150
114151 return response .to_dict ()
0 commit comments