|  | 
| 2 | 2 | 
 | 
| 3 | 3 | This package contains the code to use Vonage's Subaccount API in Python. | 
| 4 | 4 | 
 | 
| 5 |  | -It includes methods for managing Vonage subaccounts. | 
|  | 5 | +It includes methods for creating and modifying Vonage subaccounts and transferring credit, balances and numbers between subaccounts. | 
| 6 | 6 | 
 | 
| 7 | 7 | ## Usage | 
| 8 | 8 | 
 | 
| 9 | 9 | It is recommended to use this as part of the main `vonage` package. The examples below assume you've created an instance of the `vonage.Vonage` class called `vonage_client`. | 
| 10 | 10 | 
 | 
| 11 | 11 | 
 | 
| 12 |  | -<!-- ### Get Account Balance | 
|  | 12 | +### List Subaccounts | 
| 13 | 13 | 
 | 
| 14 | 14 | ```python | 
| 15 |  | -balance = vonage_client.account.get_balance() | 
| 16 |  | -print(balance) | 
|  | 15 | +response = vonage_client.subaccounts.list_subaccounts() | 
|  | 16 | +print(response.model_dump) | 
| 17 | 17 | ``` | 
| 18 | 18 | 
 | 
| 19 |  | -### Top-Up Account | 
|  | 19 | +### Create Subaccount | 
| 20 | 20 | 
 | 
| 21 | 21 | ```python | 
| 22 |  | -response = vonage_client.account.top_up(trx='1234567890') | 
|  | 22 | +from vonage_subaccounts import SubaccountOptions | 
|  | 23 | + | 
|  | 24 | +response = vonage_client.subaccounts.create_subaccount( | 
|  | 25 | +    SubaccountOptions( | 
|  | 26 | +        name='test_subaccount', secret='1234asdfA', use_primary_account_balance=False | 
|  | 27 | +    ) | 
|  | 28 | +) | 
| 23 | 29 | print(response) | 
| 24 | 30 | ``` | 
| 25 | 31 | 
 | 
| 26 |  | -### Update the Default SMS Webhook | 
| 27 |  | -
 | 
| 28 |  | -This will return a Pydantic object (`SettingsResponse`) containing multiple settings for your account. | 
|  | 32 | +### Modify a Subaccount | 
| 29 | 33 | 
 | 
| 30 | 34 | ```python | 
| 31 |  | -settings: SettingsResponse = vonage_client.account.update_default_sms_webhook( | 
| 32 |  | -    mo_callback_url='https://example.com/inbound_sms_webhook', | 
| 33 |  | -    dr_callback_url='https://example.com/delivery_receipt_webhook', | 
|  | 35 | +from vonage_subaccounts import ModifySubaccountOptions | 
|  | 36 | + | 
|  | 37 | +response = vonage_client.subaccounts.modify_subaccount( | 
|  | 38 | +    'test_subaccount', | 
|  | 39 | +    ModifySubaccountOptions( | 
|  | 40 | +        suspended=True, | 
|  | 41 | +        name='modified_test_subaccount', | 
|  | 42 | +    ), | 
| 34 | 43 | ) | 
|  | 44 | +print(response) | 
|  | 45 | +``` | 
| 35 | 46 | 
 | 
| 36 |  | -print(settings) | 
|  | 47 | +### List Balance Transfers | 
|  | 48 | + | 
|  | 49 | +```python | 
|  | 50 | +from vonage_subaccounts import ListTransfersFilter | 
|  | 51 | + | 
|  | 52 | +filter = {'start_date': '2023-08-07T10:50:44Z'} | 
|  | 53 | +response = vonage_client.subaccounts.list_balance_transfers(ListTransfersFilter(**filter)) | 
|  | 54 | +for item in response: | 
|  | 55 | +    print(item.model_dump()) | 
| 37 | 56 | ``` | 
| 38 | 57 | 
 | 
| 39 |  | -### List Secrets Associated with the Account | 
|  | 58 | +### Transfer Balance Between Subaccounts | 
| 40 | 59 | 
 | 
| 41 | 60 | ```python | 
| 42 |  | -response = vonage_client.account.list_secrets() | 
|  | 61 | +from vonage_subaccounts import TransferRequest | 
|  | 62 | + | 
|  | 63 | +request = TransferRequest( | 
|  | 64 | +    from_='test_api_key', to='test_subaccount', amount=0.02, reference='A reference' | 
|  | 65 | +) | 
|  | 66 | +response = vonage_client.subaccounts.transfer_balance(request) | 
| 43 | 67 | print(response) | 
| 44 | 68 | ``` | 
| 45 | 69 | 
 | 
| 46 |  | -### Create a New Account Secret | 
|  | 70 | +### List Credit Transfers | 
| 47 | 71 | 
 | 
| 48 | 72 | ```python | 
| 49 |  | -secret = vonage_client.account.create_secret('Mytestsecret12345') | 
| 50 |  | -print(secret) | 
|  | 73 | +from vonage_subaccounts import ListTransfersFilter | 
|  | 74 | + | 
|  | 75 | +filter = {'start_date': '2023-08-07T10:50:44Z'} | 
|  | 76 | +response = vonage_client.subaccounts.list_credit_transfers(ListTransfersFilter(**filter)) | 
|  | 77 | +for item in response: | 
|  | 78 | +    print(item.model_dump()) | 
| 51 | 79 | ``` | 
| 52 | 80 | 
 | 
| 53 |  | -### Get Information About One Secret | 
|  | 81 | +### Transfer Credit Between Subaccounts | 
| 54 | 82 | 
 | 
| 55 | 83 | ```python | 
| 56 |  | -secret = vonage_client.account.get_secret(MY_SECRET_ID) | 
| 57 |  | -print(secret) | 
| 58 |  | -``` | 
|  | 84 | +from vonage_subaccounts import TransferRequest | 
| 59 | 85 | 
 | 
| 60 |  | -### Revoke a Secret | 
|  | 86 | +request = TransferRequest( | 
|  | 87 | +    from_='test_api_key', to='test_subaccount', amount=0.02, reference='A reference' | 
|  | 88 | +) | 
|  | 89 | +response = vonage_client.subaccounts.transfer_balance(request) | 
|  | 90 | +print(response) | 
|  | 91 | +``` | 
| 61 | 92 | 
 | 
| 62 |  | -Note: it isn't possible to revoke all account secrets, there must always be one valid secret. Attempting to do so will give a 403 error. | 
|  | 93 | +### Transfer a Phone Number Between Subaccounts | 
| 63 | 94 | 
 | 
| 64 | 95 | ```python | 
| 65 |  | -client.account.revoke_secret(MY_SECRET_ID) | 
| 66 |  | -``` --> | 
|  | 96 | +from vonage_subaccounts import TransferNumberRequest | 
|  | 97 | + | 
|  | 98 | +request = TransferNumberRequest( | 
|  | 99 | +    from_='test_api_key', to='test_subaccount', number='447700900000', country='GB' | 
|  | 100 | +) | 
|  | 101 | +response = vonage_client.subaccounts.transfer_number(request) | 
|  | 102 | +print(response) | 
|  | 103 | +``` | 
0 commit comments