Vonage Subaccounts API Client
This library provides a Pythonic interface for interacting with the Vonage Subaccounts API, allowing users to programmatically manage subaccounts. It is currently at version 1.0.4 and is officially maintained, with releases typically following updates to the Vonage Subaccounts API itself.
Common errors
-
AttributeError: 'VonageSubaccounts' object has no attribute 'get_all_subaccounts'
cause Attempting to call a method that doesn't exist or is misspelled.fixDouble-check method names against the documentation. Ensure the client is correctly initialized. -
vonage.exceptions.VonageError: API Key and Secret are required
cause The `vonage.Client` was initialized without valid API credentials or they were not correctly passed.fixProvide your Vonage API Key and Secret, either directly or via environment variables, when initializing `vonage.Client`. -
TypeError: __init__ missing 1 required positional argument: 'client'
cause The `VonageSubaccounts` class was initialized without passing an instance of `vonage.Client`.fixInitialize `vonage_subaccounts.VonageSubaccounts` with a `vonage.Client` instance, e.g., `VonageSubaccounts(client=vonage_client)`. -
requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: ...
cause The API key and secret provided do not have the necessary permissions to perform the requested subaccount operation. This often happens if subaccount credentials are used instead of master account credentials.fixVerify that you are using the API Key and Secret for your *primary* Vonage account to manage subaccounts.
Warnings
- gotcha This library wraps the core `vonage` Python client. You *must* initialize `vonage.Client` first and pass it to `VonageSubaccounts`.
- breaking As this library is a wrapper for the Vonage API, changes in the underlying Vonage API or the `vonage` Python client (major versions) might introduce breaking changes to how requests are made or responses are structured.
- gotcha API Key and Secret must be for the *primary* account to manage subaccounts. Using subaccount credentials will result in permission errors for subaccount management operations.
Install
-
pip install vonage-subaccounts
Imports
- VonageSubaccounts
from vonage_subaccounts import VonageSubaccounts
- Client
from vonage import Client
Quickstart
import os
from vonage import Client
from vonage_subaccounts import VonageSubaccounts
# Ensure API_KEY and API_SECRET are set as environment variables
# e.g., export VONAGE_API_KEY='YOUR_API_KEY'
# e.g., export VONAGE_API_SECRET='YOUR_API_SECRET'
api_key = os.environ.get("VONAGE_API_KEY", "YOUR_API_KEY")
api_secret = os.environ.get("VONAGE_API_SECRET", "YOUR_API_SECRET")
if not api_key or api_key == "YOUR_API_KEY" or not api_secret or api_secret == "YOUR_API_SECRET":
print("Please set VONAGE_API_KEY and VONAGE_API_SECRET environment variables or replace placeholders.")
exit(1)
# Initialize the core Vonage client
vonage_client = Client(key=api_key, secret=api_secret)
# Initialize the Vonage Subaccounts client
subaccounts_client = VonageSubaccounts(client=vonage_client)
try:
# Example: List all subaccounts
print("Listing all subaccounts:")
all_subaccounts = subaccounts_client.get_all_subaccounts()
for subaccount in all_subaccounts:
print(f"- ID: {subaccount.get('id')}, Name: {subaccount.get('name')}, Balance: {subaccount.get('balance')}")
# Example: Create a new subaccount (uncomment to run)
# print("\nCreating a new subaccount...")
# new_subaccount = subaccounts_client.create_subaccount(name="My Test Subaccount via API")
# print(f"Created subaccount ID: {new_subaccount.get('id')}, Name: {new_subaccount.get('name')}")
except Exception as e:
print(f"An error occurred: {e}")
# Common errors might include authentication issues, invalid parameters, or API rate limits.