# POST /messages — Send Text template

> Product: **Pabbly Chatflow** (v1)
> Base URL: `https://chatflow.pabbly.com/api/v1`
> Auth: Bearer via `Authorization` header
> Canonical: `/chatflow/messages/send-text-template`

Prerequisites: You need to create a text-type template using Pabbly Chatflow or WhatsApp Manager. Hit the API with POST method and fill the following data according your requirements to send media based template message.

**Body parameters:**

| Name | Type | Required | Description |
|------|------|----------|-------------|
| to | integer | Yes | Recipient number with dialing code, e.g., 15551486942. |
| type | string | Yes | Type of message you want to send. It should be "template". |
| templateName | string | Yes | Name of the template you want to send. |
| headerParams | array | No | Parameter values that can be dynamically inserted into the template. E.g., Parameter {{1}} will be replaced in the template with the given value. |
| bodyParams | array | No | Parameter values that can be dynamically inserted into the template. You can add multiple parameters, which will be sent to the user according to their respective index. E.g., Parameter {{1}} will be replaced in the template with the given value. |
| contact | string | No | An object containing contact details. This field is used to upsert the contact matched with recipient number. |

**Example request body:**

```json
{
    "to": 1123456789,
    "type": "template",
    "templateName": "marketing_template",
    "headerParams": [
        "John"
    ],
    "bodyParams": [
        "Sir",
        "Thanks"
    ]
}
```

**Response (200)** — Send Text template:

```json
{
    "status": "success",
    "message": "Message sent",
    "data": {
        "to": "9176978XXXXX",
        "chatId": "67923764346bcdc8XXXXXXXX",
        "metaResponse": {
            "messaging_product": "whatsapp",
            "contacts": [
                {
                    "input": "9176978XXXXX",
                    "wa_id": "9176978XXXXX"
                }
            ],
            "messages": [
                {
                    "id": "wamid.HBgMOTE3Njk3ODYyMTE1FQIAERgSNTQ1MUEwQTRBRDYzXXXXXXXXXX=="
                }
            ],
            "status": 200
        }
    }
}
```

**Code examples:**

_cURL_

```curl
curl -X POST https://chatflow.pabbly.com/api/v1/messages \
  -H "Authorization: Bearer {{YOUR_API_KEY}}" \
  -H "Content-Type: application/json" \
  -d '{
    "to": 1123456789,
    "type": "template",
    "templateName": "marketing_template",
    "headerParams": [
      "John"
    ],
    "bodyParams": [
      "Sir",
      "Thanks"
    ]
  }'
```

_Ruby_

```ruby
require 'net/http'
require 'json'

uri = URI('https://chatflow.pabbly.com/api/v1/messages')
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer {{YOUR_API_KEY}}'
request['Content-Type'] = 'application/json'
request.body = "{\"to\":1123456789,\"type\":\"template\",\"templateName\":\"marketing_template\",\"headerParams\":[\"John\"],\"bodyParams\":[\"Sir\",\"Thanks\"]}"

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
  http.request(request)
end

data = JSON.parse(response.body)
```

_Python_

```python
import requests

response = requests.post(
    'https://chatflow.pabbly.com/api/v1/messages',
    headers={'Authorization': 'Bearer {{YOUR_API_KEY}}'},
    json={
    'to': 1123456789,
    'type': 'template',
    'templateName': 'marketing_template',
    'headerParams': [
        'John'
    ],
    'bodyParams': [
        'Sir',
        'Thanks'
    ]
},
)

data = response.json()
```

_PHP_

```php
<?php
$ch = curl_init('https://chatflow.pabbly.com/api/v1/messages');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer {{YOUR_API_KEY}}', 'Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"to":1123456789,"type":"template","templateName":"marketing_template","headerParams":["John"],"bodyParams":["Sir","Thanks"]}');

$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
```

_Java_

```java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

HttpClient client = HttpClient.newHttpClient();
HttpRequest.Builder builder = HttpRequest.newBuilder()
    .uri(URI.create("https://chatflow.pabbly.com/api/v1/messages"))
    .header("Authorization", "Bearer {{YOUR_API_KEY}}")
    .header("Content-Type", "application/json")
    .method("POST", HttpRequest.BodyPublishers.ofString("{\"to\":1123456789,\"type\":\"template\",\"templateName\":\"marketing_template\",\"headerParams\":[\"John\"],\"bodyParams\":[\"Sir\",\"Thanks\"]}"));

HttpRequest request = builder.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
```

_Node.js_

```node
const response = await fetch('https://chatflow.pabbly.com/api/v1/messages', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer {{YOUR_API_KEY}}',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "to": 1123456789,
    "type": "template",
    "templateName": "marketing_template",
    "headerParams": [
      "John"
    ],
    "bodyParams": [
      "Sir",
      "Thanks"
    ]
  }),
});

const data = await response.json();
```

_Go_

```go
package main

import (
    "fmt"
    "io"
    "net/http"
    "strings"
)

func main() {
    payload := strings.NewReader("{\"to\":1123456789,\"type\":\"template\",\"templateName\":\"marketing_template\",\"headerParams\":[\"John\"],\"bodyParams\":[\"Sir\",\"Thanks\"]}")
    req, _ := http.NewRequest("POST", "https://chatflow.pabbly.com/api/v1/messages", payload)
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("Authorization", "Bearer {{YOUR_API_KEY}}")

    res, _ := http.DefaultClient.Do(req)
    defer res.Body.Close()
    body, _ := io.ReadAll(res.Body)
    fmt.Println(string(body))
}
```

_.NET_

```dotnet
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://chatflow.pabbly.com/api/v1/messages");
request.Headers.TryAddWithoutValidation("Authorization", "Bearer {{YOUR_API_KEY}}");
request.Content = new StringContent("{\"to\":1123456789,\"type\":\"template\",\"templateName\":\"marketing_template\",\"headerParams\":[\"John\"],\"bodyParams\":[\"Sir\",\"Thanks\"]}");
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

var response = await client.SendAsync(request);
var data = await response.Content.ReadAsStringAsync();
Console.WriteLine(data);
```

---

**Other endpoints in Messages:**

- [POST /messages — Send Media based template](/chatflow/messages/send-media-based-template)
- [POST /messages — Send Authentication template](/chatflow/messages/send-authentication-template)
- [POST /messages — Send CTA/Buttons template](/chatflow/messages/send-cta-buttons-template)
- [POST /messages — Send Carousel template](/chatflow/messages/send-carousel-template)
- [POST /messages — Send LTO template](/chatflow/messages/send-lto-template)
- [POST /messages — Send Text Message](/chatflow/messages/send-text-message)
- [POST /messages — Send Image Message](/chatflow/messages/send-image-message)
- [POST /messages — Send Audio Message](/chatflow/messages/send-audio-message)
- [POST /messages — Send Video Message](/chatflow/messages/send-video-message)
- [POST /messages — Send Document Message](/chatflow/messages/send-document-message)
- [POST /messages — Send Single Product Message](/chatflow/messages/send-single-product-message)
- [POST /messages — Send Multi Product Message](/chatflow/messages/send-multi-product-message)
- [POST /messages — Send Catalog Message](/chatflow/messages/send-catalog-message)
- [POST /messages — Send List Message](/chatflow/messages/send-list-message)
- [POST /messages — Send CTA URL Message](/chatflow/messages/send-cta-url-message)
- [POST /messages — Send Address Request Message](/chatflow/messages/send-address-request-message)
- [POST /messages — Send Location Request Message](/chatflow/messages/send-location-request-message)

