@@ -20,10 +20,14 @@ def get_api_token(account_id: int, api_token_id: int) -> ApiToken:
2020
2121def create_api_token (account_id : int ) -> ApiTokenWithToken :
2222 # The full token value is only returned once on the response — store it securely.
23+ # Omit expires_at for the server default expiration, pass an ISO 8601
24+ # date-time for an explicit expiry, or pass expires_at=None for a token
25+ # that never expires.
2326 return api_tokens_api .create (
2427 account_id = account_id ,
2528 token_params = mt .CreateApiTokenParams (
2629 name = "My API Token" ,
30+ expires_at = "2027-06-01T00:00:00Z" ,
2731 resources = [
2832 mt .ApiTokenResource (
2933 resource_type = "account" ,
@@ -37,9 +41,22 @@ def create_api_token(account_id: int) -> ApiTokenWithToken:
3741
3842def reset_api_token (account_id : int , api_token_id : int ) -> ApiTokenWithToken :
3943 # The reset response includes the new full token value once — store it securely.
44+ # Omit token_params for the server default expiration of the new token.
4045 return api_tokens_api .reset (account_id = account_id , api_token_id = api_token_id )
4146
4247
48+ def reset_api_token_with_expiration (
49+ account_id : int , api_token_id : int
50+ ) -> ApiTokenWithToken :
51+ # Pass an ISO 8601 date-time for an explicit expiry of the new token,
52+ # or expires_at=None for a token that never expires.
53+ return api_tokens_api .reset (
54+ account_id = account_id ,
55+ api_token_id = api_token_id ,
56+ token_params = mt .ResetApiTokenParams (expires_at = "2027-06-01T00:00:00Z" ),
57+ )
58+
59+
4360def delete_api_token (account_id : int , api_token_id : int ) -> DeletedObject :
4461 return api_tokens_api .delete (account_id = account_id , api_token_id = api_token_id )
4562
@@ -57,5 +74,8 @@ def delete_api_token(account_id: int, api_token_id: int) -> DeletedObject:
5774 reset = reset_api_token (ACCOUNT_ID , created .id )
5875 print (reset )
5976
60- deleted = delete_api_token (ACCOUNT_ID , reset .id )
77+ reset_with_expiration = reset_api_token_with_expiration (ACCOUNT_ID , reset .id )
78+ print (reset_with_expiration )
79+
80+ deleted = delete_api_token (ACCOUNT_ID , reset_with_expiration .id )
6181 print (deleted )
0 commit comments