Vonage Account API Client
The `vonage-account` library provides Python bindings for interacting with the Vonage Account API. It is part of the larger Vonage Python SDK monorepo (version 4.x.x+), offering functionalities to manage account-related operations such as retrieving balance information. The SDK aims for a regular release cadence, with the main `vonage` package seeing frequent updates.
Common errors
-
ModuleNotFoundError: No module named 'nexmo'
cause The project is trying to import the old `nexmo` Python client library, which has been renamed to `vonage` since version 4.0.0 of the SDK.fixChange `import nexmo` to `import vonage` and update client instantiation from `nexmo.Client(...)` to `vonage.Vonage(auth=Auth(...))`. You might also need to update method calls. -
vonage.exceptions.AuthenticationError: 401 Unauthorized
cause The API key or secret provided to the Vonage client is incorrect, invalid, or lacks the necessary permissions for the requested operation.fixVerify your `VONAGE_API_KEY` and `VONAGE_API_SECRET` environment variables or directly passed credentials against your Vonage Dashboard. Ensure they are active and have the correct permissions for the Account API. -
vonage.exceptions.HttpRequestError: 400 Bad Request - Missing Parameters
cause The API request is missing one or more required parameters for the specific Account API endpoint being called.fixReview the Vonage API documentation for the specific Account API method you are calling (e.g., get_balance, update_settings) and ensure all mandatory parameters are included in your request.
Warnings
- breaking The Vonage Python SDK transitioned from `nexmo` to `vonage` as the top-level package and client name. Older code relying on `import nexmo` or `nexmo.Client` will raise `ModuleNotFoundError` or other API incompatibilities with current SDK versions.
- gotcha The Vonage Python SDK is a monorepo. While `vonage-account` is a separate PyPI package, its functionalities are typically accessed through the unified `vonage.Vonage` client instance (e.g., `client.account.get_balance()`). Directly importing and instantiating classes from `vonage_account` might bypass the central configuration and authentication setup of the main SDK, leading to unexpected behavior or missing features.
- deprecated Some APIs that were historically grouped under 'account' or 'pricing' in other SDKs (e.g., Java) have been removed or moved in newer SDK versions. Always consult the specific Python SDK documentation for the latest API availability.
Install
-
pip install vonage-account -
pip install vonage
Imports
- Vonage
import vonage_account.AccountClient
from vonage import Vonage, Auth
Quickstart
import os
from vonage import Vonage, Auth
# Initialize Vonage client using API key and secret from environment variables
# VONAGE_API_KEY and VONAGE_API_SECRET
client = Vonage(
auth=Auth(
api_key=os.environ.get('VONAGE_API_KEY', 'YOUR_API_KEY'),
api_secret=os.environ.get('VONAGE_API_SECRET', 'YOUR_API_SECRET')
)
)
try:
# Retrieve account balance
balance_response = client.account.get_balance()
print(f"Account Balance: {balance_response['value']} {balance_response['unit']}")
# Get account top-up status (example of another account method)
topup_response = client.account.get_topup()
print(f"Account Auto Top-up: {'Enabled' if topup_response.get('auto_topup') else 'Disabled'}")
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure VONAGE_API_KEY and VONAGE_API_SECRET are correctly set and have permissions.")