@@ -13,6 +13,7 @@ def create_agent(cls, args):
1313 api_client = create_api_client (base_path = args ["base_path" ], access_token = args ["access_token" ])
1414 users_api = UsersApi (api_client )
1515
16+ # check if agent already exists
1617 try :
1718 users = users_api .list (args ["account_id" ], email = args ["email" ], status = "Active" )
1819 if int (users .result_set_size ) > 0 :
@@ -23,9 +24,10 @@ def create_agent(cls, args):
2324 error_body = json .loads (error_body_json )
2425 error_code = error_body and "errorCode" in error_body and error_body ["errorCode" ]
2526
26- if error_code != "USER_NOT_FOUND" :
27+ if error_code not in [ "USER_NOT_FOUND" , "USER_LACKS_MEMBERSHIP" ] :
2728 raise err
2829
30+ # create new agent
2931 new_users = users_api .create (args ["account_id" ], new_users_definition = cls .new_users_definition (args ))
3032 return new_users .new_users [0 ]
3133
@@ -34,6 +36,7 @@ def create_authorization(cls, args):
3436 api_client = create_api_client (base_path = args ["base_path" ], access_token = args ["access_token" ])
3537 accounts_api = AccountsApi (api_client )
3638
39+ # check if authorization with manage permission already exists
3740 authorizations = accounts_api .get_agent_user_authorizations (
3841 args ["account_id" ],
3942 args ["agent_user_id" ],
@@ -42,6 +45,7 @@ def create_authorization(cls, args):
4245 if int (authorizations .result_set_size ) > 0 :
4346 return
4447
48+ # create authorization
4549 return accounts_api .create_user_authorization (
4650 args ["account_id" ],
4751 args ["user_id" ],
0 commit comments