Vonage HTTP Client for Python

1.5.1 · active · verified Thu Apr 16

The `vonage-http-client` is a foundational Python HTTP client library for interacting with Vonage APIs. It provides low-level request building and authentication mechanisms, supporting API key/secret and JWT-based authentication. While primarily an internal dependency of the higher-level `vonage` Python SDK, it can be used directly for specific API interactions. The current version is 1.5.1, and it has a relatively stable release cadence, with updates typically coinciding with major SDK changes or specific HTTP client enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate the `vonage-http-client` with API key/secret and make a basic GET request to a Vonage API endpoint. Remember to set `VONAGE_API_KEY` and `VONAGE_API_SECRET` environment variables. For more complex interactions, the full `vonage` Python SDK is generally preferred as it handles endpoint paths and response parsing automatically.

import os
from vonage_http_client import Client
from vonage_http_client.exceptions import VonageServerException

# NOTE: For most users, the higher-level 'vonage' SDK (pip install vonage)
# is recommended for easier API interaction.

# Retrieve API key and secret from environment variables
API_KEY = os.environ.get('VONAGE_API_KEY', '')
API_SECRET = os.environ.get('VONAGE_API_SECRET', '')

if not API_KEY or not API_SECRET:
    print("Warning: Please set VONAGE_API_KEY and VONAGE_API_SECRET environment variables.")
    print("Skipping quickstart as authentication is required.")
else:
    try:
        # Instantiate the HTTP client with your Vonage API credentials
        client = Client(
            api_key=API_KEY,
            api_secret=API_SECRET,
            # For demonstration, using a common Vonage API base URL.
            # Specific API paths (e.g., /account/balance) need to be appended manually.
            base_url="https://api.nexmo.com"
        )

        # Example: Make a GET request to a Vonage API endpoint.
        # This will likely require valid credentials and specific endpoint access.
        # A common endpoint is '/account/balance'.
        print("Attempting to fetch account balance...")
        response = client.get('/account/balance')

        print(f"Status Code: {response.status_code}")
        print(f"Response Body: {response.json()}")

    except VonageServerException as e:
        print(f"Vonage API error: {e.status_code} - {e.reason} - {e.error_response}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →