Vonage Subaccounts API Client

1.0.4 · active · verified Thu Apr 16

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

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Vonage client and then the Subaccounts client to list existing subaccounts. It requires your Vonage API Key and Secret, preferably from environment variables.

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.

view raw JSON →