Skip to main content

API Documentation: Sending Template Messages

Endpoint

POST https://api.insightssystem.com/api:hFrjh8a1/send_template_message_by_api

Description

This API allows you to send template-based messages to users via their phone numbers. You can personalize messages using variables and attach media files when applicable.


Request Headers

HeaderValueDescription
Content-Typeapplication/jsonSpecifies JSON format
AuthorizationBearer YOUR_API_KEYAPI authentication token

Request Body

The request body must be in JSON format and include the following parameters:

Parameters:

ParameterTypeRequiredDescription
templatestringYesThe unique template ID used for sending the message.
variablesobjectYesA JSON object containing dynamic placeholders for the message template.
phone_numberstringYesThe recipient's phone number in international format (e.g., +123476529999).

Variables:

The variables object contains placeholders for dynamic text replacements in the message template.

KeyTypeRequiredDescription
body1stringYesThe first variable in the template.
body2stringYesThe second variable in the template.
body3stringYesThe third variable in the template.
mediastringYesA public URL pointing to an image, video, or document to be attached to the message. Good for Google drive shareable link

Example Requests

Example 1: Sending a Template Message with Variables and Media

{
"template": "f10695a9-38d6-4f5f-8444-1f7bf52c6164",
"variables": {
"body1": "Axel",
"body2": "Shampoo",
"body3": "$1",
"media": "https://drive.google.com/file/d/1D35uTbceRPmCgwxVfBJZ2yxD2lQgs0bi/view?usp=sharing"
},
"phone_number": "+123476529999"
}

Example 2: Sending a Template Message with Only One Variable

{
"template": "b65081ed-a0f6-4aaf-b148-31719b5bc567",
"variables": {
"body1": "Edith Mireles"
},
"phone_number": "+123476529999"
}

Response

Success Response

{
"success": true,
"whatsapp_response_info": {
"contacts": [
{
"input": "+123476529999",
"wa_id": "123476529999"
}
],
"messages": [
{
"id": "wamid.HBgLMzM3NjY4NjQwMDIVAgARGBIxN0ZDREExNkE1OTdEQkUwNkQA",
"message_status": "accepted"
}
],
"messaging_product": "whatsapp"
}
}

cURL Example

curl -X POST "https://api.insightssystem.com/api:hFrjh8a1/send_template_message_by_api" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"template": "f10695a9-38d6-4f5f-8444-1f7bf52c6164",
"variables": {
"body1": "Axel",
"body2": "Shampoo",
"body3": "$1",
"media": "https://drive.google.com/file/d/1D35uTbceRPmCgwxVfBJZ2yxD2lQgs0bi/view?usp=sharing"
},
"phone_number": "123476529999"
}'

JavaScript Example

const fetch = require("node-fetch");

async function sendMessage() {
const response = await fetch(
"https://api.insightssystem.com/api:hFrjh8a1/send_template_message_by_api",
{
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_API_KEY",
},
body: JSON.stringify({
template: "f10695a9-38d6-4f5f-8444-1f7bf52c6164",
variables: {
body1: "Axel",
body2: "Shampoo",
body3: "$1",
media:
"https://drive.google.com/file/d/1D35uTbceRPmCgwxVfBJZ2yxD2lQgs0bi/view?usp=sharing",
},
phone_number: "123476529999",
}),
}
);
const data = await response.json();
console.log(data);
}

sendMessage();

Go Example

package main

import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)

type RequestBody struct {
Template string `json:"template"`
Variables map[string]string `json:"variables"`
PhoneNumber string `json:"phone_number"`
}

func main() {
requestBody := RequestBody{
Template: "f10695a9-38d6-4f5f-8444-1f7bf52c6164",
Variables: map[string]string{
"body1": "Axel",
"body2": "Shampoo",
"body3": "$1",
"media": "https://drive.google.com/file/d/1D35uTbceRPmCgwxVfBJZ2yxD2lQgs0bi/view?usp=sharing"
},
PhoneNumber: "123476529999",
}

jsonData, _ := json.Marshal(requestBody)
resp, err := http.Post("https://api.insightssystem.com/api:hFrjh8a1/send_template_message_by_api", "application/json", bytes.NewBuffer(jsonData))
if err != nil {
fmt.Println("Error:", err)
return
}
defer resp.Body.Close()
fmt.Println("Response Status:", resp.Status)
}

Notes

  • Ensure that your API key is valid and has the required permissions to send messages.
  • Phone numbers must be formatted in the international format, including the country code.
  • Templates must be pre-approved and exist in your system before sending messages.

For further assistance, contact API support.