SquareBox External API Documentation

Welcome to the SquareBox External API! This documentation covers how to generate API keys and send WhatsApp messages using our external messaging API.

Table of Contents

Overview

The SquareBox External API allows external platforms to send WhatsApp messages using secure API keys. This API is perfect for:

  • CRM integrations (Salesforce, HubSpot, etc.)

  • E-commerce platforms

  • Customer support tools

  • Marketing automation platforms

Getting Started

1. Generate API Key

  1. Log into your SquareBox account

  2. Go to SettingsAPI Keys

  3. Click "Create New API Key"

  4. Provide a name and description (e.g., "LeadSquared Integration")

  5. Important: Copy the API key immediately - it won't be shown again!

2. Get Your Line ID

  1. Go to Lines in your SquareBox dashboard

  2. Note the Line ID you want to send messages from

  3. Ensure the line is active and has sufficient credits

Authentication

Use this header:

  • X-API-Key: sb_your_api_key_here

Example:

Notes:

  • Usage is tracked per key (timestamp and IP) for audit/analytics.

  • Credit checks run before send calls; responses include estimated_cost. Actual deductions occur via webhook on status update.

Base URL

  • Production: https://app.squarebox.ai

API Endpoints

Send Text Message

Send a plain text WhatsApp message to a customer.

Headers:

Request Body:

Parameters:

  • phone_number (required): Customer's phone number with country code (e.g., "919876543210")

  • line_id (required): Your Line ID from SquareBox dashboard

  • message (required): The text message to send

  • customer_name (optional): Customer's name (creates new customer if not exists)

  • customer_email (optional): Customer's email (creates new customer if not exists)

Success Response (200):

Send Template Message

Send a WhatsApp template message with dynamic variables.

Headers:

Request Body:

Parameters:

  • phone_number (required): Customer's phone number with country code

  • line_id (required): Your Line ID from SquareBox dashboard

  • template_id (required): WhatsApp template ID (get from your templates)

  • placeholder_values (required): Dynamic values to replace in template

  • customer_name (optional): Customer's name

  • customer_email (optional): Customer's email

Success Response (200):

Send Media Message

Send a media message (image, video, audio, or document).

Headers (any one):

Form Data:

  • phone_number: "919876543210"

  • line_id: "123"

  • media_type: "image" (options: image, video, audio, document)

  • media_url: "https://example.com/image.jpg"

  • caption: "Check out our latest product!" (optional)

  • customer_name: "John Doe" (optional)

  • customer_email: "john@example.com" (optional)

Success Response (200):

Get Customer Info

Retrieve customer information and conversation status.

Headers:

Query Parameters:

  • phone_number (required): Customer's phone number with country code

  • line_id (required): Your Line ID from SquareBox dashboard

Success Response (200):

Get Credit Balance

Check your current credit balance.

Headers:

Query Parameters:

  • line_id (required): Your Line ID from SquareBox dashboard

Success Response (200):

Estimate Message Cost

Get cost estimation for sending messages to specific countries.

Headers:

Query Parameters:

  • line_id (required): Your Line ID from SquareBox dashboard

  • country_code (optional): Country code (e.g., "91" for India, "1" for US)

  • message_type (optional): Type of message (text, template, media)

Success Response (200):

Get Available Templates

Retrieve all available WhatsApp templates for your line.

Headers:

Query Parameters:

  • line_id (required): Your Line ID from SquareBox dashboard

Success Response (200):

Bulk Send Messages

Send multiple messages in a single API call (up to 50 messages).

Headers:

Request Body:

Success Response (200):

Webhooks

Configure Webhook URL

Set up a webhook URL to receive real-time updates about message status and cost deductions.

Headers:

Request Body:

Success Response (200):

Get Webhook Configuration

Retrieve your current webhook configuration.

Headers (any one):

Success Response (200):

Test Webhook Configuration

Test your webhook configuration by sending a test payload.

Headers (any one):

Success Response (200):

Webhook Events

Your webhook endpoint will receive the following events:

Message Status Updated

Cost Deducted

Webhook Security

All webhook payloads include a signature header for verification:

To verify the signature:

Cost Management

How Costs Work

  1. Cost Estimation: Use the estimate_cost endpoint to check message costs before sending

  2. Credit Check: The API checks if you have sufficient credits before sending messages

  3. Cost Deduction: Credits are deducted via webhook when message status becomes 'sent'

  4. Real-time Updates: Receive webhook notifications when costs are deducted

Cost Structure

  • Country-based pricing: Different costs for different countries

  • Message type pricing: Templates may have different costs than text messages

  • Real-time deduction: Only charged when message is successfully sent

  • Transparent billing: Full cost breakdown in webhook notifications

Rate Limiting

  • 100 requests per hour per API key

  • 10 requests per minute for all endpoints

  • When limits are exceeded, you will receive HTTP 429 with an error message

Examples

cURL Examples

Send Text Message

Check Credit Balance

Estimate Cost

Bulk Send Messages

Configure Webhook

JavaScript Example

Python Example

Error Handling

Error Response Format

Common Error Codes

Code
Description
Solution

400

Bad Request

Check request parameters

401

Unauthorized

Verify API key is correct

402

Payment Required

Add credits to your account

403

Forbidden

Check if API key has permissions

404

Not Found

Verify line_id or template_id exists

422

Unprocessable Entity

Check phone number format

429

Too Many Requests

Wait before making more requests

500

Internal Server Error

Contact support

Common Errors

Insufficient Credits

Rate Limit Exceeded

Invalid Phone Number

Support

For API support and questions:

  • Email: api-support@squarebox.ai

  • Documentation: https://docs.squarebox.ai

  • Status Page: https://status.squarebox.ai


Last updated: January 15, 2024