# Send Template Message

> Send a template-based message to users via their phone numbers

> [!WARNING]
>
> This page documents the legacy API. New integrations use API v1: [Send a message (API v1)](/api-reference/v1/messages/send-message)

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

## Authorizations

**Authorization** `string` (required)

Bearer authentication header of the form `Bearer <token>`. Your WhatsAble API token

## Body

**template** `string` (required)

The unique template ID used for sending the message

**variables** `object` (required)

A JSON object containing dynamic placeholders for the message template. The keys should match the variables in your template. Common variable keys include:
- body1, body2, body3: Text variables for message content
- media: URL for image, video, or document attachments
- visit_website: URL's parameter for the dynamic button link

Each value: `string`. Value for the template variable

**phone_number** `string` (required)

The recipient's phone number in international format (e.g., +123476529999)

## Response

`200`: Message sent successfully

**success** `boolean`

Indicates if the message was sent successfully

**whatsapp_response_info** `object`

  **contacts** `object[]`

    **input** `string`

    The input phone number

    **wa_id** `string`

    The WhatsApp ID

  **messages** `object[]`

    **id** `string`

    The WhatsApp message ID

    **message_status** `string`

    The status of the message

  **messaging_product** `string`

  The messaging product (e.g., whatsapp)

## Errors

- `400`: Bad Request
- `401`: Unauthorized

```bash cURL
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 JavaScript
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 Go
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)
}
```