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

  1. Log in to your dashboard here.
  2. Navigate to Settings > API Keys.
  3. Click Generate API Key, save the key securely.
  4. Use this key in the apiKey field of the request.

2. Create an API Campaign

Follow these steps to create an API campaign:

  1. Navigate to the Campaigns section in your dashboard.
  2. Click + Campaign.
  3. Choose the API Campaign type.
  4. Fill in the following fields:
    • Campaign Name: A unique name for the campaign.
    • Template Name: Select an approved WhatsApp template.
  5. Save the campaign.
  • Note: Ensure your campaign is "Active" for it to be available via the API.

POSThttps://api.sandeshai.com/whatsapp/campaign/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

POST
/whatsapp/campaign/api/
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

  1. Ensure your campaignName is active and matches an existing API campaign in the system.
  2. Contacts will be created automatically if they don't already exist in the platform.
  3. 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.
  4. media URLs must be publicly accessible.
  5. Ensure the number of templateVariables matches the placeholders in the template.
  6. Success: Returns a 200 OK status.
  7. Failure: Returns a 500 Internal Server Error.
  8. 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!

Was this page helpful?