### Install Sendly Go SDK Source: https://sendly.live/docs/quickstart Installs the official Sendly SDK for Go using the go get command. This is the first step to integrating Sendly into your Go application. ```bash go get github.com/SendlyHQ/sendly-go/v3 ``` -------------------------------- ### Install Sendly Ruby Gem Source: https://sendly.live/docs/quickstart Installs the official Sendly gem for Ruby. This is the first step to integrating Sendly into your Ruby application. ```bash gem install sendly ``` -------------------------------- ### Install and Use Sendly CLI Source: https://sendly.live/docs/quickstart Provides commands to install the Sendly CLI globally, log in to your account, send a test SMS, check your credit balance, and listen for webhooks locally. ```bash # Install globally npm install -g @sendly/cli # Login to your account sendly login # Send a test message sendly sms send --to "+15005550000" --text "Hello from CLI!" # Check your credit balance sendly credits # Listen for webhooks locally (no ngrok needed!) sendly webhooks listen --forward http://localhost:3000/webhook ``` -------------------------------- ### Install Sendly Node.js SDK Source: https://sendly.live/docs/quickstart Installs the official Sendly SDK for Node.js using npm. This is the first step to integrating Sendly into your Node.js application. ```bash npm install @sendly/node ``` -------------------------------- ### Install Sendly Python SDK Source: https://sendly.live/docs/quickstart Installs the official Sendly SDK for Python using pip. This is the first step to integrating Sendly into your Python application. ```bash pip install sendly ``` -------------------------------- ### Set Up Express Server and Install Dependencies (Python) Source: https://sendly.live/docs/tutorials/webhooks This snippet shows the initial setup for a webhook server using Python. It creates a directory, sets up a virtual environment, and installs necessary libraries like Flask and Sendly. This is the first step in building a local webhook endpoint. ```bash 1mkdir webhook-server && cd webhook-server 2python -m venv venv 3source venv/bin/activate # On Windows: venv\Scripts\activate 4pip install flask sendly ``` -------------------------------- ### Install and Run Sendly CLI for Local Webhook Listening Source: https://sendly.live/docs/concepts/local-development This snippet demonstrates how to install the Sendly CLI, log in to your account, and start a local webhook listener. The listener forwards incoming events to a specified local server URL, providing a secure and efficient way to test webhooks during development. ```bash # Install the CLI npm install -g @sendly/cli # Login to your account sendly login # Start listening for webhooks sendly webhooks listen --forward http://localhost:3000/webhook # Output: # Webhook listener ready! # Forwarding to: http://localhost:3000/webhook # Events: message.sent, message.delivered, message.failed, message.bounced # # Webhook Secret: # whsec_abc123... # # Waiting for events... (Ctrl+C to quit) ``` -------------------------------- ### Start Local Listener with Sendly CLI Source: https://sendly.live/docs/webhooks Installs the Sendly CLI, logs in, and starts a local listener to forward events to a specified local server endpoint. Supports filtering events. ```bash # Install CLI (if not already installed) npm install -g @sendly/cli # Login to your account sendly login # Start listening and forward to your local server sendly webhooks listen --forward http://localhost:3000/webhook # Filter specific events sendly webhooks listen --forward http://localhost:3000/webhook \ --events message.delivered,message.failed ``` -------------------------------- ### Create Sendly Live API Key (Node.js) Source: https://sendly.live/docs/going-live This code example shows how to create a new live API key using the Sendly Node.js SDK. It requires a test API key for the creation process and specifies permissions for the new live key. ```typescript import Sendly from '@sendly/node'; // Use your test key to create a live key const sendly = new Sendly('sk_test_v1_your_key'); const apiKey = await sendly.apiKeys.create({ name: 'Production', type: 'live', permissions: ['messages:send', 'credits:read'] }); console.log(`Created live key: ${apiKey.key}`); console.log(`Key ID: ${apiKey.id}`); // Now use the new live key for production const liveClient = new Sendly(apiKey.key); ``` -------------------------------- ### Configure Sendly for Production (Node.js) Source: https://sendly.live/docs/going-live This Node.js example illustrates how to configure the Sendly client for production use, typically by reading the API key from environment variables. It also provides an alternative explicit configuration for different environments (development, staging, production) and includes a function to send transactional messages with error handling. ```typescript import Sendly from '@sendly/node'; // Production configuration - reads from environment const sendly = new Sendly(process.env.SENDLY_API_KEY); // Alternative: Explicit configuration for different environments const config = { development: 'sk_test_v1_dev_key', staging: 'sk_test_v1_staging_key', production: 'sk_live_v1_production_key' }; const apiKey = config[process.env.NODE_ENV] || config.development; const client = new Sendly(apiKey); // Production-ready message with error handling async function sendMessage(to: string, text: string) { try { const message = await client.messages.send({ to, text, messageType: 'transactional' }); console.log(`Message sent successfully: ${message.id}`); return message; } catch (error) { console.error('Failed to send message:', error); throw error; } } ``` -------------------------------- ### Setup Python Flask Webhook Server Source: https://sendly.live/docs/tutorials/webhooks This snippet demonstrates how to set up a basic webhook server using Python and the Flask framework. It includes code for installing dependencies, creating a virtual environment, and handling incoming webhook requests with signature verification. ```bash 1mkdir webhook-server && cd webhook-server 2python -m venv venv 3source venv/bin/activate # On Windows: venv\Scripts\activate 4pip install flask sendly ``` ```python 1from flask import Flask, request, jsonify 2import hmac 3import hashlib 4 5app = Flask(__name__) 6 7WEBHOOK_SECRET = 'your_webhook_secret_here' 8 9def verify_signature(payload, signature): 10 expected_sig = 'v1=' + hmac.new( 11 WEBHOOK_SECRET.encode(), 12 payload, 13 hashlib.sha256 14 ).hexdigest() 15 16 return hmac.compare_digest(signature, expected_sig) 17 18@app.route('/webhook', methods=['POST']) 19def webhook(): 20 signature = request.headers.get('X-Sendly-Signature') 21 22 if not signature or not verify_signature(request.data, signature): 23 print('Invalid signature') 24 return 'Invalid signature', 401 25 26 event = request.json 27 28 event_type = event.get('type') 29 if event_type == 'message.sent': 30 print(f"Message sent: {event['data']['id']}") 31 elif event_type == 'message.delivered': 32 print(f"Message delivered: {event['data']['id']}") 33 elif event_type == 'message.failed': 34 print(f"Message failed: {event['data']['id']}, {event['data'].get('error')}") 35 elif event_type == 'message.bounced': 36 print(f"Message bounced: {event['data']['id']}") 37 else: 38 print(f"Unknown event: {event_type}") 39 40 return 'OK', 200 41 42if __name__ == '__main__': 43 app.run(port=3000) ``` -------------------------------- ### Send First SMS using Sendly Node.js SDK Source: https://sendly.live/docs/quickstart Demonstrates how to send a transactional SMS message using the Sendly Node.js SDK. It requires an API key and specifies the recipient, message text, and message type. ```typescript import Sendly from '@sendly/node'; const sendly = new Sendly('sk_test_v1_your_key'); const message = await sendly.messages.send({ to: '+15005550000', text: 'Hello from Sendly!', messageType: 'transactional' }); console.log('Sent:', message.id); ``` -------------------------------- ### Install Sendly SDK (Bash) Source: https://sendly.live/docs/tutorials/send-sms Installs the Sendly SDK for Python. This command creates a new directory for your project and then installs the necessary package using pip. ```bash 1mkdir my-sms-app && cd my-sms-app 2pip install sendly ``` -------------------------------- ### Expose Local Server with Sendly CLI (Bash) Source: https://sendly.live/docs/tutorials/webhooks This bash script demonstrates how to use the Sendly CLI to expose your local webhook server to the internet for development and testing. It covers installing the CLI, logging in, and starting a listener that forwards events to your local endpoint. This eliminates the need for external tunneling services like ngrok. ```bash 1# Install the CLI 2npm install -g @sendly/cli 3 4# Login 5sendly login 6 7# Start listening for webhooks 8sendly webhooks listen --forward http://localhost:3000/webhook 9 10# Output: 11# Webhook URL: https://hooks.sendly.live/cli/abc123 12# Secret: whsec_xxx 13# Listening for events... ``` -------------------------------- ### Start Sendly Webhook Listener with CLI Source: https://sendly.live/docs/how-to/test-webhooks-locally This command starts a local listener for Sendly webhooks. It can be configured to forward events to a specified local endpoint and filter by event type. Prerequisites include the Sendly CLI installed and a Sendly account. ```bash # Login if you haven't already sendly login # Start listening (defaults to localhost:3000/webhook) sendly webhooks listen # Or specify a custom endpoint sendly webhooks listen --forward http://localhost:8080/api/webhooks # Filter specific events sendly webhooks listen --forward http://localhost:3000/webhook \ --events message.delivered,message.failed ``` -------------------------------- ### Configure Sendly for Production (Node.js) Source: https://sendly.live/docs/going-live This snippet illustrates how to configure the Sendly client for production environments using environment variables. It provides an example of reading the API key from `process.env.SENDLY_API_KEY` and includes an alternative explicit configuration for different environments. ```typescript import Sendly from '@sendly/node'; // Production configuration - reads from environment const sendly = new Sendly(process.env.SENDLY_API_KEY); // Alternative: Explicit configuration for different environments const config = { development: 'sk_test_v1_dev_key', staging: 'sk_test_v1_staging_key', production: 'sk_live_v1_production_key' }; const apiKey = config[process.env.NODE_ENV] || config.development; const client = new Sendly(apiKey); // Production-ready message with error handling async function sendMessage(to: string, text: string) { try { const message = await client.messages.send({ to, text, messageType: 'transactional' }); console.log(`Message sent successfully: ${message.id}`); return message; } catch (error) { console.error('Failed to send message:', error); throw error; } } ``` -------------------------------- ### Create Next.js Project and Install Sendly SDK Source: https://sendly.live/docs/tutorials/otp This snippet shows the commands to create a new Next.js application with TypeScript, Tailwind CSS, and the App Router, and then installs the Sendly Node.js SDK. Ensure Node.js v18+ is installed. ```bash npx create-next-app@latest phone-verification --typescript --tailwind --app --no-src-dir cd phone-verification npm install @sendly/node ``` -------------------------------- ### Create Next.js App and Install Sendly SDK Source: https://sendly.live/docs/tutorials/otp This snippet shows the bash commands to create a new Next.js application with TypeScript and Tailwind CSS, and then install the Sendly Node.js SDK. It sets up the basic project structure for the verification flow. ```bash 1npx create-next-app@latest phone-verification --typescript --tailwind --app --no-src-dir 2cd phone-verification 3 4# Install the Sendly SDK 5npm install @sendly/node ``` -------------------------------- ### Install Sendly Ruby Gem Source: https://sendly.live/docs/sdks Installs the official Ruby SDK for Sendly using gem or adds it to the Gemfile. ```bash gem install sendly # or add to Gemfile gem 'sendly' ``` -------------------------------- ### Install Sendly SDK for .NET Source: https://sendly.live/docs/sdks Installs the official .NET SDK for Sendly. This SDK supports asynchronous operations for sending messages. ```bash 1dotnet add package Sendly 2# or via Package Manager 3Install-Package Sendly ``` -------------------------------- ### Verify Sendly CLI Installation Source: https://sendly.live/docs/cli Verify the Sendly CLI installation by checking its version. This command confirms that the CLI has been installed correctly and displays the installed version number. ```bash sendly --version # @sendly/cli/3.12.2 darwin-arm64 node-v20.x.x ``` -------------------------------- ### Install Sendly Node.js SDK Source: https://sendly.live/docs/sdks Installs the official Node.js SDK for Sendly. Supports npm, yarn, and pnpm package managers. ```bash npm install @sendly/node # or yarn add @sendly/node # or pnpm add @sendly/node ``` -------------------------------- ### Install Sendly PHP Package Source: https://sendly.live/docs/sdks Installs the official PHP SDK for Sendly using Composer. Requires PHP 8.1+. ```bash composer require sendly/sendly-php ``` -------------------------------- ### Install Sendly SDK for Node.js Source: https://sendly.live/docs/sdks Installs the Sendly Node.js SDK using npm, yarn, or pnpm. This SDK allows for sending SMS, scheduling messages, and batch sending. ```bash 1npm install @sendly/node 2# or 3yarn add @sendly/node 4# or 5pnpm add @sendly/node ``` -------------------------------- ### Install Sendly SDK for Ruby Source: https://sendly.live/docs/sdks Installs the Sendly Ruby gem either globally or by adding it to your Gemfile. This SDK is used for sending SMS messages. ```bash 1gem install sendly 2# or add to Gemfile 3gem 'sendly' ``` -------------------------------- ### Start Local Webhook Listener Source: https://sendly.live/docs/cli Starts a local webhook listener that forwards events to a specified URL. It automatically creates a secure tunnel using localtunnel and registers it with Sendly. Supports custom paths and filtering events. ```bash # Forward webhooks to localhost:3000 sendly webhooks listen --forward http://localhost:3000/webhook # Custom path and specific events sendly webhooks listen --forward http://localhost:3000/api/webhooks \ --events message.delivered,message.failed ``` -------------------------------- ### Install Sendly SDK for PHP Source: https://sendly.live/docs/sdks Installs the Sendly PHP SDK using Composer. This SDK enables sending SMS messages via the Sendly API. ```bash 1composer require sendly/sendly-php ``` -------------------------------- ### Register Webhook (Python SDK) Source: https://sendly.live/docs/tutorials/webhooks This code example shows how to register a new webhook endpoint using the Sendly Python SDK. It specifies the URL, the events to subscribe to, and an optional description. ```APIDOC ## POST /v2/webhooks ### Description Registers a new webhook endpoint with Sendly to receive event notifications. You can specify which events you want to be notified about. ### Method POST ### Endpoint `/v2/webhooks` ### Parameters #### Request Body - **url** (string) - Required - The URL of your webhook endpoint. - **events** (array of strings) - Required - A list of event types to subscribe to (e.g., 'message.sent', 'message.delivered'). - **description** (string) - Optional - A description for the webhook. ### Request Example ```json { "url": "https://yourapp.com/webhook", "events": [ "message.sent", "message.delivered", "message.failed", "message.bounced" ], "description": "Production webhook" } ``` ### Response #### Success Response (200) - **id** (string) - The unique identifier for the created webhook. - **secret** (string) - The secret key used for signing webhook events. Keep this secure. #### Response Example ```json { "id": "whk_abc123", "secret": "whsec_xxx" } ``` ``` -------------------------------- ### Install Sendly CLI Source: https://sendly.live/docs/cli Install the Sendly CLI globally using npm, yarn, pnpm, or Homebrew. The latest release includes batch CSV cloud upload, enhanced status commands, and improved error handling. ```bash npm install -g @sendly/cli ``` ```bash yarn global add @sendly/cli ``` ```bash pnpm add -g @sendly/cli ``` ```bash brew tap SendlyHQ/tap brew install sendly ``` -------------------------------- ### Install Sendly SDK for Python Source: https://sendly.live/docs/sdks Installs the Sendly Python SDK using pip. This SDK facilitates sending SMS, scheduling messages, and batch sending. ```bash 1pip install sendly ``` -------------------------------- ### Webhook Payload Example Source: https://sendly.live/docs/llms Example JSON payload for a webhook event, specifically 'verification.verified'. Includes event type and data about the verification. ```json { "event": "verification.verified", "data": { "id": "ver_abc123", "phone": "+15551234567", "status": "verified", "verified_at": "2026-01-05T12:07:30Z" } } ``` -------------------------------- ### Configure CLI Settings Source: https://sendly.live/docs/cli Manages CLI configuration settings. You can list all settings, get a specific value, set a new value, or switch between test and live environments. ```bash # View all settings sendly config list # Get specific setting sendly config get apiKey # Set a value sendly config set defaultFrom "MyApp" # Switch between test and live environments sendly config set environment test # Use test API key (sandbox) sendly config set environment live # Use live API key (production) sendly config get environment # Check current mode ``` -------------------------------- ### Manage Sendly Configuration Source: https://sendly.live/docs/cli View, get, and set configuration settings using 'sendly config' commands. This includes managing API keys, environments (test/live), and other preferences. ```bash sendly config list sendly config get apiKey sendly config set defaultFrom "MyApp" sendly config set environment test sendly config set environment live sendly config get environment ``` -------------------------------- ### Run Development Server (npm) Source: https://sendly.live/docs/tutorials/otp Starts the development server for the Sendly Live project using npm. This command allows for local development and testing. After running, the application can be accessed at `http://localhost:3000`. ```bash npm run dev # Open http://localhost:3000 ``` -------------------------------- ### Check Account Credit Balance using cURL Source: https://sendly.live/docs/index This example shows how to check your remaining SMS credit balance using the Sendly API with cURL. It requires your API key for authentication and makes a GET request to the credits endpoint. This is useful for monitoring your account usage and planning credit purchases. ```bash curl https://sendly.live/api/v1/credits \ -H "Authorization: Bearer sk_live_YOUR_API_KEY" ``` -------------------------------- ### Initialize Sendly Client (Python) Source: https://sendly.live/docs/tutorials/send-sms Initializes the Sendly client with your API key. Replace 'sk_test_v1_your_key_here' with your actual test API key. This is a prerequisite for sending messages. ```python from sendly import Sendly # Replace with your test API key client = Sendly('sk_test_v1_your_key_here') ``` -------------------------------- ### Python: Initialize Sendly Client with API Key Source: https://sendly.live/docs/auth Shows how to set up the Sendly Python client with a live API key. The client manages authentication internally for all API calls. Remember to substitute 'sk_live_YOUR_API_KEY' with your valid API key. ```python import Sendly client = Sendly('sk_live_YOUR_API_KEY') # The SDK handles authentication automatically ``` -------------------------------- ### Create Sendly Live API Key (Node.js) Source: https://sendly.live/docs/going-live This code snippet shows how to create a new live API key for Sendly using the Node.js SDK. It utilizes an existing test API key to initiate the creation process. The resulting live key and its ID are logged to the console, and a new Sendly client is initialized with the created live key. ```typescript import Sendly from '@sendly/node'; // Use your test key to create a live key const sendly = new Sendly('sk_test_v1_your_key'); const apiKey = await sendly.apiKeys.create({ name: 'Production', type: 'live', permissions: ['messages:send', 'credits:read'] }); console.log(`Created live key: ${apiKey.key}`); console.log(`Key ID: ${apiKey.id}`); // Now use the new live key for production const liveClient = new Sendly(apiKey.key); ``` -------------------------------- ### Register Webhook via SDK (Python) Source: https://sendly.live/docs/tutorials/webhooks This Python snippet illustrates how to register a webhook with Sendly for production environments using their SDK. It initializes the Sendly client with an API key and then calls the `create` method to register a webhook URL, specifying the events to subscribe to and providing a descriptive name. The output includes the newly created webhook's ID and secret. ```python 1from sendly import Sendly 2 3client = Sendly('sk_live_v1_your_key_here') 4 5webhook = client.webhooks.create( 6 url='https://yourapp.com/webhook', 7 events=[ 8 'message.sent', 9 'message.delivered', 10 'message.failed', 11 'message.bounced', 12 ], 13 description='Production webhook' 14) 15 16print('Webhook created!') 17print(f'ID: {webhook.id}') 18print(f'Secret: {webhook.secret}') ``` -------------------------------- ### Create a New Webhook Source: https://sendly.live/docs/cli Creates a new webhook with a specified URL, events to listen for, and mode (test, live, or all). This is used to set up new event notifications. ```bash # Create a new webhook sendly webhooks create \ --url "https://your-server.com/webhooks" \ --events message.sent,message.delivered \ --mode all ``` -------------------------------- ### Configure Sendly API Key Source: https://sendly.live/docs/tutorials/otp This snippet illustrates how to add your Sendly API key to the project's environment variables. It's recommended to use a test key for development, which enables sandbox mode. ```bash SENDLY_API_KEY=sk_test_v1_your_key_here ``` -------------------------------- ### Error Response Example Source: https://sendly.live/docs/llms Example of an error response from the Sendly API, indicating insufficient credits. Includes error code, message, required, and available credits. ```json { "error": "insufficient_credits", "message": "Not enough credits to send message", "required": 2, "available": 0 } ``` -------------------------------- ### View Configuration with Sendly CLI Source: https://sendly.live/docs/cli Displays the current configuration settings for the Sendly CLI. This command is useful for verifying settings like the API key or other configured options. ```bash sendly config list ``` -------------------------------- ### Node.js: Initialize Sendly Client with API Key Source: https://sendly.live/docs/auth Demonstrates how to initialize the Sendly Node.js client using a live API key. The SDK automatically handles authentication for subsequent requests. Ensure you replace 'sk_live_YOUR_API_KEY' with your actual key. ```javascript import Sendly from '@sendly/node'; const client = new Sendly('sk_live_YOUR_API_KEY'); // The SDK handles authentication automatically ``` -------------------------------- ### Run Python Script (Bash) Source: https://sendly.live/docs/tutorials/send-sms Executes a Python script that sends an SMS message. This command runs the 'send.py' file and displays the output, including the message ID and status. ```bash python send.py # Output: # Message sent! # ID: msg_abc123... # Status: delivered ``` -------------------------------- ### Get Message API Source: https://sendly.live/docs/api Retrieve a specific message by ID. ```APIDOC ## GET /api/v1/messages/:id ### Description Retrieve a specific message by ID. ### Method GET ### Endpoint `/api/v1/messages/:id` ### Parameters #### Path Parameters - **id** (string) - Required - The message ID to retrieve ### Response #### Success Response (200) - **id** (string) - Unique message identifier - **status** (string) - Message status - **deliveredAt** (string) - Timestamp of delivery (if delivered) ### Response Example ```json { "id": "msg_abc123", "status": "delivered", "deliveredAt": "2026-01-01T10:00:00Z" } ``` ``` -------------------------------- ### Get Deliveries Source: https://sendly.live/docs/api Retrieves a list of delivery attempts for a specific webhook. ```APIDOC ## GET /webhooks/{webhook_id}/deliveries ### Description Retrieves a list of delivery attempts for a specific webhook. ### Method GET ### Endpoint /webhooks/{webhook_id}/deliveries ### Parameters #### Path Parameters - **webhook_id** (string) - Required - The ID of the webhook whose deliveries are to be retrieved. #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **deliveries** (array) - A list of delivery attempt objects. #### Response Example ```json { "deliveries": [ { "id": "del_123", "webhook_id": "wh_abc123", "event": "message.delivered", "status": "success", "timestamp": "2023-10-27T10:00:00Z" } ] } ``` ``` -------------------------------- ### Get Message Source: https://sendly.live/docs/api Retrieve details for a specific message using its ID. ```APIDOC ## GET /messages/{messageId} ### Description Retrieve detailed information about a specific SMS message using its unique identifier. ### Method GET ### Endpoint /messages/{messageId} ### Parameters #### Path Parameters - **messageId** (string) - Required - The unique identifier of the message to retrieve. ### Response #### Success Response (200) - **id** (string) - The unique identifier for the message. - **status** (string) - The current status of the message. - **deliveredAt** (string) - Timestamp when the message was delivered (ISO 8601 format), if applicable. #### Response Example ```json { "id": "msg_abc123", "status": "delivered", "deliveredAt": "2023-10-27T10:30:00Z" } ``` ``` -------------------------------- ### Create and Use Custom OTP Template (TypeScript) Source: https://sendly.live/docs/verify This TypeScript example shows how to create a custom OTP template using the Sendly client, publish it for use, and then send a verification code using the newly created template. It assumes the 'sendly' library is available. ```typescript // Create a custom template const template = await sendly.templates.create({ name: 'My Custom OTP', text: '{{app_name}}: Use {{code}} to verify. Valid 5 min.' }); // Publish it for use await sendly.templates.publish(template.id); // Use it await sendly.verify.send({ to: '+15551234567', templateId: template.id }); ``` -------------------------------- ### Get Event Types Source: https://sendly.live/docs/api Retrieves a list of all available event types that can be subscribed to. ```APIDOC ## GET /webhooks/event-types ### Description Retrieves a list of all available event types that can be subscribed to. ### Method GET ### Endpoint /webhooks/event-types ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **event_types** (array of strings) - A list of available event types. #### Response Example ```json { "event_types": [ "message.sent", "message.delivered", "message.failed" ] } ``` ``` -------------------------------- ### List and Filter Webhooks Source: https://sendly.live/docs/cli Lists all configured webhooks or filters them by mode (test or live). This command is useful for managing and reviewing your webhook configurations. ```bash # List all webhooks sendly webhooks list # Filter by mode (test, live, or all) sendly webhooks list --mode test sendly webhooks list --mode live ``` -------------------------------- ### Get Account Source: https://sendly.live/docs/api Retrieves your account information, including verification status and usage limits. ```APIDOC ## GET /api/v1/account ### Description Get your account information including verification status and limits. ### Method GET ### Endpoint `/api/v1/account` ### Response #### Success Response (200 OK) - **isVerified** (boolean) - Indicates if the account is verified. - **limits** (object) - An object containing account usage limits. - **sms_sent_daily** (integer) - Daily limit for SMS messages sent. - **sms_sent_monthly** (integer) - Monthly limit for SMS messages sent. ### Request Example ```typescript import Sendly from '@sendly/node'; const sendly = new Sendly('sk_live_YOUR_KEY'); const account = await sendly.account.get(); console.log('Verified:', account.isVerified); console.log('Limits:', account.limits); ``` #### Response Example ```json { "isVerified": true, "limits": { "sms_sent_daily": 10000, "sms_sent_monthly": 100000 } } ``` ``` -------------------------------- ### Get Credit Transactions Source: https://sendly.live/docs/api Retrieve your credit transaction history, including purchases and usage. ```APIDOC ## Get Credit Transactions GET `/api/v1/credits/transactions` ### Description Get credit transaction history including purchases and usage. ### Method GET ### Endpoint `/api/v1/credits/transactions` ### Query Parameters - **limit** (number) - Optional - Maximum number of transactions to return. - **offset** (number) - Optional - Number of transactions to skip. - **type** (string) - Optional - Filter by transaction type ('purchase', 'sms_sent', 'refund'). ### Response #### Success Response (200) - **transactions** (array) - An array of transaction objects. - **type** (string) - Type of transaction ('purchase', 'sms_sent', 'refund') - **amount** (number) - Amount of credits involved in the transaction - **timestamp** (string) - ISO 8601 timestamp of the transaction #### Response Example ```json { "transactions": [ { "type": "sms_sent", "amount": -10, "timestamp": "2023-10-27T10:00:00Z" }, { "type": "purchase", "amount": 500, "timestamp": "2023-10-26T15:30:00Z" } ] } ``` ``` -------------------------------- ### Get Batch Status Source: https://sendly.live/docs/api Retrieve the status and progress of a specific batch send operation. ```APIDOC ## Get Batch Status GET `/api/v1/messages/batch/:id` ### Description Get the status and progress of a batch send operation. ### Method GET ### Endpoint `/api/v1/messages/batch/:id` #### Path Parameters - **id** (string) - Required - The ID of the batch to retrieve status for. ### Response #### Success Response (200) - **status** (string) - Current status of the batch ('pending', 'processing', 'completed', 'partial', 'failed') - **total** (number) - Total messages in the batch - **sent** (number) - Successfully sent messages - **failed** (number) - Failed messages #### Response Example ```json { "status": "completed", "total": 100, "sent": 98, "failed": 2 } ``` ``` -------------------------------- ### Get Credit Balance Source: https://sendly.live/docs/api Retrieve your current credit balance, including reserved and available amounts. ```APIDOC ## Get Credit Balance GET `/api/v1/credits` ### Description Get your current credit balance. ### Method GET ### Endpoint `/api/v1/credits` ### Response #### Success Response (200) - **balance** (number) - Total credit balance - **reservedBalance** (number) - Credits reserved for pending operations - **availableBalance** (number) - Credits available for use #### Response Example ```json { "balance": 1000, "reservedBalance": 50, "availableBalance": 950 } ``` ``` -------------------------------- ### Error Handling Source: https://sendly.live/docs/llms Details common error codes and their meanings, along with an example of the error response structure. ```APIDOC ## Error Handling ### Description Common error codes to handle in your integration. | Code | Description | |---------------------|-------------------------------------| | invalid_api_key | API key is invalid or revoked | | invalid_phone_number| Phone number format invalid | | insufficient_credits| Not enough credits | | rate_limit_exceeded | Too many requests | | quiet_hours_violation| Marketing outside 8am-9pm | ### Error Response #### Response Example ```json { "error": "insufficient_credits", "message": "Not enough credits to send message", "required": 2, "available": 0 } ``` ``` -------------------------------- ### Webhook Handler (Python/Flask) Source: https://sendly.live/docs/tutorials/webhooks This snippet demonstrates how to create a webhook endpoint using Flask in Python. It includes logic to verify incoming webhook signatures for security and to handle different message event types. ```APIDOC ## POST /webhook ### Description An endpoint to receive real-time notifications from Sendly about message events. It verifies the signature of incoming requests and processes different event types. ### Method POST ### Endpoint `/webhook` ### Parameters #### Headers - **X-Sendly-Signature** (string) - Required - The signature of the webhook payload, used for verification. #### Request Body - **type** (string) - Required - The type of the event (e.g., 'message.sent', 'message.delivered'). - **data** (object) - Required - The event data, containing details about the message. - **id** (string) - The ID of the message. - **error** (string) - Optional - The error details if the event type is 'message.failed'. ### Request Example ```json { "type": "message.delivered", "data": { "id": "msg_abc123" } } ``` ### Response #### Success Response (200) - **Status**: OK - **Body**: An empty response with a 200 status code indicating successful processing. #### Response Example ``` OK ``` #### Error Response (401) - **Status**: Invalid signature - **Body**: A string indicating an invalid signature if the `X-Sendly-Signature` header does not match the expected signature. ``` -------------------------------- ### Get Account Information Source: https://sendly.live/docs/api Retrieves details about the current account, including verification status and usage limits. ```APIDOC ## GET /account ### Description Retrieves details about the current account, including verification status and usage limits. ### Method GET ### Endpoint /account ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **isVerified** (boolean) - Indicates if the account is verified. - **limits** (object) - An object containing information about account limits. #### Response Example ```json { "isVerified": true, "limits": { "sms_per_month": 100000 } } ``` ``` -------------------------------- ### Get Credit Balance Source: https://sendly.live/docs/credits Retrieve your current credit balance and lifetime credits associated with your Sendly account. ```APIDOC ## GET /api/credits ### Description Retrieve your current credit balance and lifetime credits. ### Method GET ### Endpoint /api/credits ### Parameters #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **balance** (string) - Your current available credit balance. - **lifetimeCredits** (string) - The total number of credits you have had over your lifetime. #### Response Example ```json { "balance": "5000", "lifetimeCredits": "15000" } ``` ``` -------------------------------- ### Get Account Information Source: https://sendly.live/docs/api Retrieves details about the user's account, including verification status and usage limits. ```typescript import Sendly from '@sendly/node'; const sendly = new Sendly('sk_live_YOUR_KEY'); const account = await sendly.account.get(); console.log('Verified:', account.isVerified); console.log('Limits:', account.limits); ``` -------------------------------- ### Send Sandbox SMS Message (Python) Source: https://sendly.live/docs/tutorials/send-sms Sends a test SMS message to a sandbox number using the Sendly SDK. This code demonstrates how to send a message and handle potential errors. Sandbox numbers do not send real SMS or use credits. ```python from sendly import Sendly client = Sendly('sk_test_v1_your_key_here') try: message = client.messages.send( to='+15005550006', # Sandbox number - always succeeds text='Hello from Sendly! This is my first message.' ) print('Message sent!') print(f'ID: {message.id}') print(f'Status: {message.status}') except Exception as error: print(f'Error: {error}') ``` -------------------------------- ### Get Batch API Source: https://sendly.live/docs/batch Retrieve the status and details of a specific batch using its batch ID. ```APIDOC ## GET /messages/batch/{batchId} ### Description Retrieves the status and details of a specific batch using its unique batch ID. ### Method GET ### Endpoint /messages/batch/{batchId} ### Parameters #### Path Parameters - **batchId** (string) - Required - The unique identifier of the batch to retrieve. ### Response #### Success Response (200) - **batchId** (string) - The unique identifier for the batch. - **status** (string) - The current status of the batch (e.g., 'completed', 'processing', 'failed'). - **total** (integer) - The total number of messages in the batch. - **queued** (integer) - The number of messages currently queued. - **sent** (integer) - The number of messages successfully sent. - **failed** (integer) - The number of messages that failed to send. - **creditsUsed** (integer) - The number of credits consumed by the batch. - **messages** (array) - An array of message objects, each containing details like `id`, `to`, and `status`. - **completedAt** (string) - The timestamp when the batch processing was completed. #### Response Example ```json { "batchId": "batch_abc123", "status": "completed", "total": 3, "queued": 0, "sent": 3, "failed": 0, "creditsUsed": 3, "messages": [ {"id": "msg_1", "to": "+15551234567", "status": "queued"}, {"id": "msg_2", "to": "+15559876543", "status": "queued"}, {"id": "msg_3", "to": "+15551112222", "status": "queued"} ], "completedAt": "2026-01-19T10:30:05Z" } ``` ``` -------------------------------- ### Get Webhook Delivery History Source: https://sendly.live/docs/api Retrieves the delivery history for a specific webhook, including any failed attempts and retry statuses. ```bash curl "https://sendly.live/api/v1/webhooks/wh_abc123/deliveries" \ -H "Authorization: Bearer sk_live_YOUR_KEY" ``` -------------------------------- ### Trigger Test Events with Sendly CLI (Bash) Source: https://sendly.live/docs/tutorials/webhooks This bash script provides commands to trigger various test events for your Sendly webhook. By running these commands in a separate terminal, you can simulate message delivery, failure, and bounce events. The output confirms that your server should be logging these events, allowing for easy testing and debugging of your webhook handler. ```bash 1# In another terminal, trigger test events: 2sendly trigger message.delivered 3sendly trigger message.failed 4sendly trigger message.bounced 5 6# Your server should log each event! ``` -------------------------------- ### Get Available Webhook Event Types Source: https://sendly.live/docs/api Fetches a list of all available event types that can be subscribed to via webhooks, along with their descriptions. ```bash curl "https://sendly.live/api/v1/webhooks/event-types" \ -H "Authorization: Bearer sk_live_YOUR_KEY" ``` -------------------------------- ### GET /api/credits/packages Source: https://sendly.live/docs/packages Retrieves a list of available credit packages, including their credit amounts, prices, and any bonus credits offered. ```APIDOC ## GET /api/credits/packages ### Description Retrieves a list of available credit packages with their corresponding credit amounts, prices, and bonus credits. ### Method GET ### Endpoint `/api/credits/packages` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **id** (string) - Unique identifier for the credit package. - **credits** (integer) - The number of credits included in the package. - **priceInCents** (integer) - The price of the package in cents. - **bonusCredits** (integer) - The number of bonus credits, if any. - **bonusPercent** (integer, optional) - The percentage of bonus credits, if applicable. - **displayName** (string) - A human-readable display name for the package. #### Response Example ```json [ { "id": "credits_500", "credits": 500, "priceInCents": 500, "bonusCredits": 0, "displayName": "$5 - 500 credits" }, { "id": "credits_5500", "credits": 5500, "priceInCents": 5000, "bonusCredits": 500, "bonusPercent": 10, "displayName": "$50 - 5,500 credits (10% bonus)" } ] ``` ```