API Reference - Send Template Message
This guide explains how to send WhatsApp template messages via API campaigns using SandeshAI. With this API, you can seamlessly integrate your CRM, website, or other systems with SandeshAI to automate WhatsApp messaging. Whether it’s sending notifications, transactional messages, or marketing campaigns, SandeshAI API provides the flexibility to handle it all efficiently.
Prerequisites
Before using this API, ensure the following are set up:
1. Generate an API Key
- Log in to your dashboard here.
- Navigate to Settings > API Keys.
- Click Generate API Key, save the key securely.
- Use this key in the
apiKey
field of the request.
2. Create an API Campaign
Follow these steps to create an API campaign:
- Navigate to the Campaigns section in your dashboard.
- Click + Campaign.
- Choose the API Campaign type.
- Fill in the following fields:
- Campaign Name: A unique name for the campaign.
- Template Name: Select an approved WhatsApp template.
- Save the campaign.
- Note: Ensure your campaign is "Active" for it to be available via the API.
API Endpoint
Use this endpoint to send WhatsApp template messages programmatically. The API supports creating contacts and sending template messages asynchronously.
Request Payload
Required Fields
- Name
apiKey
- Type
- string
- Description
Your unique API key for authentication. Obtainable from your SandeshAI dashboard under Settings > API Key.
- Name
campaignName
- Type
- string
- Description
Name of the active API campaign to be used for sending the message. Obtainable from your SandeshAI dashboard under Campaign.
- Name
whatsappNumber
- Type
- string
- Description
Recipient's WhatsApp number, including country code. Example:
917805076045
.
- Name
contactName
- Type
- string
- Description
Full name of the recipient.
Optional Fields
- Name
attributes
- Type
- object
- Description
Key-value pairs for custom attributes associated with the contact. You can add as many attributes as you want. Example:
{"Source": "Instagram" "City": "Mumbai", "age": "25" }
.
- Name
media
- Type
- string
- Description
URL of media to send with the message (if applicable).
- Name
templateVariables
- Type
- array
- Description
An array of variables to populate placeholders in the template. Example:
["Rishabh", "25% discount"]
.
Request Example
import requests
url = "https://api.sandeshai.com/whatsapp/campaign/api/"
data = {
"apiKey": "your_api_key_here",
"campaignName": "First Campaign",
"whatsappNumber": "917805076045",
"contactName": "Rishabh Gupta",
"attributes": {"Source": "Instagram", "City": "Mumbai", "age": "25" }, # Optional
"media": "https://example.com/media/image.jpg", # Optional
"templateVariables": ["Rishabh", "25% discount"], # Optional
}
response = requests.post(url, json=data)
print(response.json())
Success Response: 200 OK
{
"msg": "Message Sent Successfully!"
}
Error Response: 500 Internal Server Error
{
"msg": "Error Message"
}
Notes
- Ensure your
campaignName
is active and matches an existing API campaign in the system. - Contacts will be created automatically if they don't already exist in the platform.
attributes
do not necessarily need to be predefined in the system to be applied to the contact. If an attribute does not exist, it will automatically be created.media
URLs must be publicly accessible.- Ensure the number of
templateVariables
matches the placeholders in the template. - Success: Returns a 200 OK status.
- Failure: Returns a 500 Internal Server Error.
- An inactive or invalid API key will return a 401 Unauthorized error.
Feel free to reach out to SandeshAI Support if you have further questions or need assistance!