Send a Whatsapp message
POST
/
messages
/
whatsapp
Send a Whatsapp message
curl --request POST \
--url https://api.telnyx.com/v2/messages/whatsapp \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"from": "+13125551234",
"to": "+13125551234",
"whatsapp_message": {
"audio": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"sticker": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"interactive": {
"action": {
"name": "<string>",
"button": "<string>",
"buttons": [
{
"type": "reply",
"reply": {
"title": "<string>",
"id": "<string>"
}
}
],
"catalog_id": "<string>",
"product_retailer_id": "<string>",
"sections": [
{
"product_items": [
{
"product_retailer_id": "<string>"
}
],
"rows": [
{
"id": "<string>",
"title": "<string>",
"description": "<string>"
}
],
"title": "<string>"
}
],
"mode": "<string>",
"parameters": {
"display_text": "<string>",
"url": "<string>"
},
"cards": [
{
"card_index": 123,
"type": "cta_url",
"header": {
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
}
},
"body": {
"text": "<string>"
},
"action": {
"product_retailer_id": "<string>",
"catalog_id": "<string>"
}
}
]
},
"body": {
"text": "<string>"
},
"footer": {
"text": "<string>"
},
"header": {
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"text": "<string>",
"sub_text": "<string>"
}
},
"location": {
"latitude": "<string>",
"longitude": "<string>",
"name": "<string>",
"address": "<string>"
},
"contacts": [
{
"addresses": [
{
"street": "<string>",
"city": "<string>",
"state": "<string>",
"zip": "<string>",
"country": "<string>",
"country_code": "<string>",
"type": "<string>"
}
],
"birthday": "<string>",
"emails": [
{
"email": "<string>",
"type": "<string>"
}
],
"name": "<string>",
"org": {
"company": "<string>",
"department": "<string>",
"title": "<string>"
},
"phones": [
{
"phone": "<string>",
"type": "<string>",
"wa_id": "<string>"
}
],
"urls": [
{
"url": "<string>",
"type": "<string>"
}
]
}
],
"reaction": {
"message_id": "<string>",
"emoji": "<string>"
},
"biz_opaque_callback_data": "<string>",
"template": {
"template_id": "019cd44b-3a1c-781b-956e-bd33e9fd2ac6",
"name": "order_confirmation",
"components": [
{
"index": 123,
"parameters": [
{
"text": "<string>"
}
]
}
]
}
},
"type": "WHATSAPP",
"webhook_url": "<string>",
"messaging_profile_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'import requests
url = "https://api.telnyx.com/v2/messages/whatsapp"
payload = {
"from": "+13125551234",
"to": "+13125551234",
"whatsapp_message": {
"audio": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"sticker": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"interactive": {
"action": {
"name": "<string>",
"button": "<string>",
"buttons": [
{
"type": "reply",
"reply": {
"title": "<string>",
"id": "<string>"
}
}
],
"catalog_id": "<string>",
"product_retailer_id": "<string>",
"sections": [
{
"product_items": [{ "product_retailer_id": "<string>" }],
"rows": [
{
"id": "<string>",
"title": "<string>",
"description": "<string>"
}
],
"title": "<string>"
}
],
"mode": "<string>",
"parameters": {
"display_text": "<string>",
"url": "<string>"
},
"cards": [
{
"card_index": 123,
"type": "cta_url",
"header": {
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
}
},
"body": { "text": "<string>" },
"action": {
"product_retailer_id": "<string>",
"catalog_id": "<string>"
}
}
]
},
"body": { "text": "<string>" },
"footer": { "text": "<string>" },
"header": {
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"text": "<string>",
"sub_text": "<string>"
}
},
"location": {
"latitude": "<string>",
"longitude": "<string>",
"name": "<string>",
"address": "<string>"
},
"contacts": [
{
"addresses": [
{
"street": "<string>",
"city": "<string>",
"state": "<string>",
"zip": "<string>",
"country": "<string>",
"country_code": "<string>",
"type": "<string>"
}
],
"birthday": "<string>",
"emails": [
{
"email": "<string>",
"type": "<string>"
}
],
"name": "<string>",
"org": {
"company": "<string>",
"department": "<string>",
"title": "<string>"
},
"phones": [
{
"phone": "<string>",
"type": "<string>",
"wa_id": "<string>"
}
],
"urls": [
{
"url": "<string>",
"type": "<string>"
}
]
}
],
"reaction": {
"message_id": "<string>",
"emoji": "<string>"
},
"biz_opaque_callback_data": "<string>",
"template": {
"template_id": "019cd44b-3a1c-781b-956e-bd33e9fd2ac6",
"name": "order_confirmation",
"components": [
{
"index": 123,
"parameters": [{ "text": "<string>" }]
}
]
}
},
"type": "WHATSAPP",
"webhook_url": "<string>",
"messaging_profile_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
from: '+13125551234',
to: '+13125551234',
whatsapp_message: {
audio: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
document: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
image: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
sticker: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
video: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
interactive: {
action: {
name: '<string>',
button: '<string>',
buttons: [{type: 'reply', reply: {title: '<string>', id: '<string>'}}],
catalog_id: '<string>',
product_retailer_id: '<string>',
sections: [
{
product_items: [{product_retailer_id: '<string>'}],
rows: [{id: '<string>', title: '<string>', description: '<string>'}],
title: '<string>'
}
],
mode: '<string>',
parameters: {display_text: '<string>', url: '<string>'},
cards: [
{
card_index: 123,
type: 'cta_url',
header: {
image: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
video: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
}
},
body: JSON.stringify({text: '<string>'}),
action: {product_retailer_id: '<string>', catalog_id: '<string>'}
}
]
},
body: JSON.stringify({text: '<string>'}),
footer: {text: '<string>'},
header: {
document: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
image: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
video: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
text: '<string>',
sub_text: '<string>'
}
},
location: {
latitude: '<string>',
longitude: '<string>',
name: '<string>',
address: '<string>'
},
contacts: [
{
addresses: [
{
street: '<string>',
city: '<string>',
state: '<string>',
zip: '<string>',
country: '<string>',
country_code: '<string>',
type: '<string>'
}
],
birthday: '<string>',
emails: [{email: '<string>', type: '<string>'}],
name: '<string>',
org: {company: '<string>', department: '<string>', title: '<string>'},
phones: [{phone: '<string>', type: '<string>', wa_id: '<string>'}],
urls: [{url: '<string>', type: '<string>'}]
}
],
reaction: {message_id: '<string>', emoji: '<string>'},
biz_opaque_callback_data: '<string>',
template: {
template_id: '019cd44b-3a1c-781b-956e-bd33e9fd2ac6',
name: 'order_confirmation',
components: [{index: 123, parameters: [{text: '<string>'}]}]
}
},
type: 'WHATSAPP',
webhook_url: '<string>',
messaging_profile_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a'
})
};
fetch('https://api.telnyx.com/v2/messages/whatsapp', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.telnyx.com/v2/messages/whatsapp",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'from' => '+13125551234',
'to' => '+13125551234',
'whatsapp_message' => [
'audio' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'document' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'image' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'sticker' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'video' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'interactive' => [
'action' => [
'name' => '<string>',
'button' => '<string>',
'buttons' => [
[
'type' => 'reply',
'reply' => [
'title' => '<string>',
'id' => '<string>'
]
]
],
'catalog_id' => '<string>',
'product_retailer_id' => '<string>',
'sections' => [
[
'product_items' => [
[
'product_retailer_id' => '<string>'
]
],
'rows' => [
[
'id' => '<string>',
'title' => '<string>',
'description' => '<string>'
]
],
'title' => '<string>'
]
],
'mode' => '<string>',
'parameters' => [
'display_text' => '<string>',
'url' => '<string>'
],
'cards' => [
[
'card_index' => 123,
'type' => 'cta_url',
'header' => [
'image' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'video' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
]
],
'body' => [
'text' => '<string>'
],
'action' => [
'product_retailer_id' => '<string>',
'catalog_id' => '<string>'
]
]
]
],
'body' => [
'text' => '<string>'
],
'footer' => [
'text' => '<string>'
],
'header' => [
'document' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'image' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'video' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'text' => '<string>',
'sub_text' => '<string>'
]
],
'location' => [
'latitude' => '<string>',
'longitude' => '<string>',
'name' => '<string>',
'address' => '<string>'
],
'contacts' => [
[
'addresses' => [
[
'street' => '<string>',
'city' => '<string>',
'state' => '<string>',
'zip' => '<string>',
'country' => '<string>',
'country_code' => '<string>',
'type' => '<string>'
]
],
'birthday' => '<string>',
'emails' => [
[
'email' => '<string>',
'type' => '<string>'
]
],
'name' => '<string>',
'org' => [
'company' => '<string>',
'department' => '<string>',
'title' => '<string>'
],
'phones' => [
[
'phone' => '<string>',
'type' => '<string>',
'wa_id' => '<string>'
]
],
'urls' => [
[
'url' => '<string>',
'type' => '<string>'
]
]
]
],
'reaction' => [
'message_id' => '<string>',
'emoji' => '<string>'
],
'biz_opaque_callback_data' => '<string>',
'template' => [
'template_id' => '019cd44b-3a1c-781b-956e-bd33e9fd2ac6',
'name' => 'order_confirmation',
'components' => [
[
'index' => 123,
'parameters' => [
[
'text' => '<string>'
]
]
]
]
]
],
'type' => 'WHATSAPP',
'webhook_url' => '<string>',
'messaging_profile_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.telnyx.com/v2/messages/whatsapp"
payload := strings.NewReader("{\n \"from\": \"+13125551234\",\n \"to\": \"+13125551234\",\n \"whatsapp_message\": {\n \"audio\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"sticker\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"interactive\": {\n \"action\": {\n \"name\": \"<string>\",\n \"button\": \"<string>\",\n \"buttons\": [\n {\n \"type\": \"reply\",\n \"reply\": {\n \"title\": \"<string>\",\n \"id\": \"<string>\"\n }\n }\n ],\n \"catalog_id\": \"<string>\",\n \"product_retailer_id\": \"<string>\",\n \"sections\": [\n {\n \"product_items\": [\n {\n \"product_retailer_id\": \"<string>\"\n }\n ],\n \"rows\": [\n {\n \"id\": \"<string>\",\n \"title\": \"<string>\",\n \"description\": \"<string>\"\n }\n ],\n \"title\": \"<string>\"\n }\n ],\n \"mode\": \"<string>\",\n \"parameters\": {\n \"display_text\": \"<string>\",\n \"url\": \"<string>\"\n },\n \"cards\": [\n {\n \"card_index\": 123,\n \"type\": \"cta_url\",\n \"header\": {\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n }\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"action\": {\n \"product_retailer_id\": \"<string>\",\n \"catalog_id\": \"<string>\"\n }\n }\n ]\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"footer\": {\n \"text\": \"<string>\"\n },\n \"header\": {\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"text\": \"<string>\",\n \"sub_text\": \"<string>\"\n }\n },\n \"location\": {\n \"latitude\": \"<string>\",\n \"longitude\": \"<string>\",\n \"name\": \"<string>\",\n \"address\": \"<string>\"\n },\n \"contacts\": [\n {\n \"addresses\": [\n {\n \"street\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"zip\": \"<string>\",\n \"country\": \"<string>\",\n \"country_code\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"birthday\": \"<string>\",\n \"emails\": [\n {\n \"email\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"name\": \"<string>\",\n \"org\": {\n \"company\": \"<string>\",\n \"department\": \"<string>\",\n \"title\": \"<string>\"\n },\n \"phones\": [\n {\n \"phone\": \"<string>\",\n \"type\": \"<string>\",\n \"wa_id\": \"<string>\"\n }\n ],\n \"urls\": [\n {\n \"url\": \"<string>\",\n \"type\": \"<string>\"\n }\n ]\n }\n ],\n \"reaction\": {\n \"message_id\": \"<string>\",\n \"emoji\": \"<string>\"\n },\n \"biz_opaque_callback_data\": \"<string>\",\n \"template\": {\n \"template_id\": \"019cd44b-3a1c-781b-956e-bd33e9fd2ac6\",\n \"name\": \"order_confirmation\",\n \"components\": [\n {\n \"index\": 123,\n \"parameters\": [\n {\n \"text\": \"<string>\"\n }\n ]\n }\n ]\n }\n },\n \"type\": \"WHATSAPP\",\n \"webhook_url\": \"<string>\",\n \"messaging_profile_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.telnyx.com/v2/messages/whatsapp")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"from\": \"+13125551234\",\n \"to\": \"+13125551234\",\n \"whatsapp_message\": {\n \"audio\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"sticker\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"interactive\": {\n \"action\": {\n \"name\": \"<string>\",\n \"button\": \"<string>\",\n \"buttons\": [\n {\n \"type\": \"reply\",\n \"reply\": {\n \"title\": \"<string>\",\n \"id\": \"<string>\"\n }\n }\n ],\n \"catalog_id\": \"<string>\",\n \"product_retailer_id\": \"<string>\",\n \"sections\": [\n {\n \"product_items\": [\n {\n \"product_retailer_id\": \"<string>\"\n }\n ],\n \"rows\": [\n {\n \"id\": \"<string>\",\n \"title\": \"<string>\",\n \"description\": \"<string>\"\n }\n ],\n \"title\": \"<string>\"\n }\n ],\n \"mode\": \"<string>\",\n \"parameters\": {\n \"display_text\": \"<string>\",\n \"url\": \"<string>\"\n },\n \"cards\": [\n {\n \"card_index\": 123,\n \"type\": \"cta_url\",\n \"header\": {\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n }\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"action\": {\n \"product_retailer_id\": \"<string>\",\n \"catalog_id\": \"<string>\"\n }\n }\n ]\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"footer\": {\n \"text\": \"<string>\"\n },\n \"header\": {\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"text\": \"<string>\",\n \"sub_text\": \"<string>\"\n }\n },\n \"location\": {\n \"latitude\": \"<string>\",\n \"longitude\": \"<string>\",\n \"name\": \"<string>\",\n \"address\": \"<string>\"\n },\n \"contacts\": [\n {\n \"addresses\": [\n {\n \"street\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"zip\": \"<string>\",\n \"country\": \"<string>\",\n \"country_code\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"birthday\": \"<string>\",\n \"emails\": [\n {\n \"email\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"name\": \"<string>\",\n \"org\": {\n \"company\": \"<string>\",\n \"department\": \"<string>\",\n \"title\": \"<string>\"\n },\n \"phones\": [\n {\n \"phone\": \"<string>\",\n \"type\": \"<string>\",\n \"wa_id\": \"<string>\"\n }\n ],\n \"urls\": [\n {\n \"url\": \"<string>\",\n \"type\": \"<string>\"\n }\n ]\n }\n ],\n \"reaction\": {\n \"message_id\": \"<string>\",\n \"emoji\": \"<string>\"\n },\n \"biz_opaque_callback_data\": \"<string>\",\n \"template\": {\n \"template_id\": \"019cd44b-3a1c-781b-956e-bd33e9fd2ac6\",\n \"name\": \"order_confirmation\",\n \"components\": [\n {\n \"index\": 123,\n \"parameters\": [\n {\n \"text\": \"<string>\"\n }\n ]\n }\n ]\n }\n },\n \"type\": \"WHATSAPP\",\n \"webhook_url\": \"<string>\",\n \"messaging_profile_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/messages/whatsapp")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"from\": \"+13125551234\",\n \"to\": \"+13125551234\",\n \"whatsapp_message\": {\n \"audio\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"sticker\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"interactive\": {\n \"action\": {\n \"name\": \"<string>\",\n \"button\": \"<string>\",\n \"buttons\": [\n {\n \"type\": \"reply\",\n \"reply\": {\n \"title\": \"<string>\",\n \"id\": \"<string>\"\n }\n }\n ],\n \"catalog_id\": \"<string>\",\n \"product_retailer_id\": \"<string>\",\n \"sections\": [\n {\n \"product_items\": [\n {\n \"product_retailer_id\": \"<string>\"\n }\n ],\n \"rows\": [\n {\n \"id\": \"<string>\",\n \"title\": \"<string>\",\n \"description\": \"<string>\"\n }\n ],\n \"title\": \"<string>\"\n }\n ],\n \"mode\": \"<string>\",\n \"parameters\": {\n \"display_text\": \"<string>\",\n \"url\": \"<string>\"\n },\n \"cards\": [\n {\n \"card_index\": 123,\n \"type\": \"cta_url\",\n \"header\": {\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n }\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"action\": {\n \"product_retailer_id\": \"<string>\",\n \"catalog_id\": \"<string>\"\n }\n }\n ]\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"footer\": {\n \"text\": \"<string>\"\n },\n \"header\": {\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"text\": \"<string>\",\n \"sub_text\": \"<string>\"\n }\n },\n \"location\": {\n \"latitude\": \"<string>\",\n \"longitude\": \"<string>\",\n \"name\": \"<string>\",\n \"address\": \"<string>\"\n },\n \"contacts\": [\n {\n \"addresses\": [\n {\n \"street\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"zip\": \"<string>\",\n \"country\": \"<string>\",\n \"country_code\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"birthday\": \"<string>\",\n \"emails\": [\n {\n \"email\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"name\": \"<string>\",\n \"org\": {\n \"company\": \"<string>\",\n \"department\": \"<string>\",\n \"title\": \"<string>\"\n },\n \"phones\": [\n {\n \"phone\": \"<string>\",\n \"type\": \"<string>\",\n \"wa_id\": \"<string>\"\n }\n ],\n \"urls\": [\n {\n \"url\": \"<string>\",\n \"type\": \"<string>\"\n }\n ]\n }\n ],\n \"reaction\": {\n \"message_id\": \"<string>\",\n \"emoji\": \"<string>\"\n },\n \"biz_opaque_callback_data\": \"<string>\",\n \"template\": {\n \"template_id\": \"019cd44b-3a1c-781b-956e-bd33e9fd2ac6\",\n \"name\": \"order_confirmation\",\n \"components\": [\n {\n \"index\": 123,\n \"parameters\": [\n {\n \"text\": \"<string>\"\n }\n ]\n }\n ]\n }\n },\n \"type\": \"WHATSAPP\",\n \"webhook_url\": \"<string>\",\n \"messaging_profile_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"record_type": "message",
"direction": "outbound",
"id": "4031938e-60e4-4235-a8dd-0b1c55a23e7a",
"type": "WHATSAPP",
"organization_id": "9f61d8e1-7687-4d6d-9cae-9ff682985983",
"messaging_profile_id": "4001781e-626f-4a41-a914-b1b682150f94",
"from": {
"phone_number": "<string>",
"carrier": "<string>"
},
"to": [
{
"phone_number": "+13125551234",
"status": "queued",
"carrier": "Verizon Wireless",
"line_type": "Wireless"
}
],
"body": {
"audio": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"sticker": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"interactive": {
"action": {
"name": "<string>",
"button": "<string>",
"buttons": [
{
"type": "reply",
"reply": {
"title": "<string>",
"id": "<string>"
}
}
],
"catalog_id": "<string>",
"product_retailer_id": "<string>",
"sections": [
{
"product_items": [
{
"product_retailer_id": "<string>"
}
],
"rows": [
{
"id": "<string>",
"title": "<string>",
"description": "<string>"
}
],
"title": "<string>"
}
],
"mode": "<string>",
"parameters": {
"display_text": "<string>",
"url": "<string>"
},
"cards": [
{
"card_index": 123,
"type": "cta_url",
"header": {
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
}
},
"body": {
"text": "<string>"
},
"action": {
"product_retailer_id": "<string>",
"catalog_id": "<string>"
}
}
]
},
"body": {
"text": "<string>"
},
"footer": {
"text": "<string>"
},
"header": {
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"text": "<string>",
"sub_text": "<string>"
}
},
"location": {
"latitude": "<string>",
"longitude": "<string>",
"name": "<string>",
"address": "<string>"
},
"contacts": [
{
"addresses": [
{
"street": "<string>",
"city": "<string>",
"state": "<string>",
"zip": "<string>",
"country": "<string>",
"country_code": "<string>",
"type": "<string>"
}
],
"birthday": "<string>",
"emails": [
{
"email": "<string>",
"type": "<string>"
}
],
"name": "<string>",
"org": {
"company": "<string>",
"department": "<string>",
"title": "<string>"
},
"phones": [
{
"phone": "<string>",
"type": "<string>",
"wa_id": "<string>"
}
],
"urls": [
{
"url": "<string>",
"type": "<string>"
}
]
}
],
"reaction": {
"message_id": "<string>",
"emoji": "<string>"
},
"biz_opaque_callback_data": "<string>",
"text": {
"body": "Hello from Telnyx!",
"preview_url": false
},
"template": {
"template_id": "019cd44b-3a1c-781b-956e-bd33e9fd2ac6",
"name": "order_confirmation",
"language": {
"code": "en_US",
"policy": "deterministic"
},
"components": [
{
"index": 123,
"parameters": [
{
"text": "<string>"
}
]
}
]
}
},
"encoding": "utf-8",
"received_at": "2023-11-07T05:31:56Z",
"wait_seconds": 0.5
}
}{
"errors": [
{
"code": "<string>",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>",
"parameter": "<string>"
},
"meta": {}
}
]
}Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Whatsapp message body
Phone number in +E.164 format associated with Whatsapp account
Example:
"+13125551234"
Phone number in +E.164 format
Example:
"+13125551234"
Show child attributes
Show child attributes
Message type - must be set to "WHATSAPP"
Available options:
WHATSAPP Example:
"WHATSAPP"
The URL where webhooks related to this message will be sent.
Messaging profile ID - required if the 'from' number is not SMS-enabled
Response
Successful operation
Show child attributes
Show child attributes
Was this page helpful?
⌘I
Send a Whatsapp message
curl --request POST \
--url https://api.telnyx.com/v2/messages/whatsapp \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"from": "+13125551234",
"to": "+13125551234",
"whatsapp_message": {
"audio": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"sticker": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"interactive": {
"action": {
"name": "<string>",
"button": "<string>",
"buttons": [
{
"type": "reply",
"reply": {
"title": "<string>",
"id": "<string>"
}
}
],
"catalog_id": "<string>",
"product_retailer_id": "<string>",
"sections": [
{
"product_items": [
{
"product_retailer_id": "<string>"
}
],
"rows": [
{
"id": "<string>",
"title": "<string>",
"description": "<string>"
}
],
"title": "<string>"
}
],
"mode": "<string>",
"parameters": {
"display_text": "<string>",
"url": "<string>"
},
"cards": [
{
"card_index": 123,
"type": "cta_url",
"header": {
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
}
},
"body": {
"text": "<string>"
},
"action": {
"product_retailer_id": "<string>",
"catalog_id": "<string>"
}
}
]
},
"body": {
"text": "<string>"
},
"footer": {
"text": "<string>"
},
"header": {
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"text": "<string>",
"sub_text": "<string>"
}
},
"location": {
"latitude": "<string>",
"longitude": "<string>",
"name": "<string>",
"address": "<string>"
},
"contacts": [
{
"addresses": [
{
"street": "<string>",
"city": "<string>",
"state": "<string>",
"zip": "<string>",
"country": "<string>",
"country_code": "<string>",
"type": "<string>"
}
],
"birthday": "<string>",
"emails": [
{
"email": "<string>",
"type": "<string>"
}
],
"name": "<string>",
"org": {
"company": "<string>",
"department": "<string>",
"title": "<string>"
},
"phones": [
{
"phone": "<string>",
"type": "<string>",
"wa_id": "<string>"
}
],
"urls": [
{
"url": "<string>",
"type": "<string>"
}
]
}
],
"reaction": {
"message_id": "<string>",
"emoji": "<string>"
},
"biz_opaque_callback_data": "<string>",
"template": {
"template_id": "019cd44b-3a1c-781b-956e-bd33e9fd2ac6",
"name": "order_confirmation",
"components": [
{
"index": 123,
"parameters": [
{
"text": "<string>"
}
]
}
]
}
},
"type": "WHATSAPP",
"webhook_url": "<string>",
"messaging_profile_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
'import requests
url = "https://api.telnyx.com/v2/messages/whatsapp"
payload = {
"from": "+13125551234",
"to": "+13125551234",
"whatsapp_message": {
"audio": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"sticker": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"interactive": {
"action": {
"name": "<string>",
"button": "<string>",
"buttons": [
{
"type": "reply",
"reply": {
"title": "<string>",
"id": "<string>"
}
}
],
"catalog_id": "<string>",
"product_retailer_id": "<string>",
"sections": [
{
"product_items": [{ "product_retailer_id": "<string>" }],
"rows": [
{
"id": "<string>",
"title": "<string>",
"description": "<string>"
}
],
"title": "<string>"
}
],
"mode": "<string>",
"parameters": {
"display_text": "<string>",
"url": "<string>"
},
"cards": [
{
"card_index": 123,
"type": "cta_url",
"header": {
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
}
},
"body": { "text": "<string>" },
"action": {
"product_retailer_id": "<string>",
"catalog_id": "<string>"
}
}
]
},
"body": { "text": "<string>" },
"footer": { "text": "<string>" },
"header": {
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": True
},
"text": "<string>",
"sub_text": "<string>"
}
},
"location": {
"latitude": "<string>",
"longitude": "<string>",
"name": "<string>",
"address": "<string>"
},
"contacts": [
{
"addresses": [
{
"street": "<string>",
"city": "<string>",
"state": "<string>",
"zip": "<string>",
"country": "<string>",
"country_code": "<string>",
"type": "<string>"
}
],
"birthday": "<string>",
"emails": [
{
"email": "<string>",
"type": "<string>"
}
],
"name": "<string>",
"org": {
"company": "<string>",
"department": "<string>",
"title": "<string>"
},
"phones": [
{
"phone": "<string>",
"type": "<string>",
"wa_id": "<string>"
}
],
"urls": [
{
"url": "<string>",
"type": "<string>"
}
]
}
],
"reaction": {
"message_id": "<string>",
"emoji": "<string>"
},
"biz_opaque_callback_data": "<string>",
"template": {
"template_id": "019cd44b-3a1c-781b-956e-bd33e9fd2ac6",
"name": "order_confirmation",
"components": [
{
"index": 123,
"parameters": [{ "text": "<string>" }]
}
]
}
},
"type": "WHATSAPP",
"webhook_url": "<string>",
"messaging_profile_id": "3c90c3cc-0d44-4b50-8888-8dd25736052a"
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
from: '+13125551234',
to: '+13125551234',
whatsapp_message: {
audio: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
document: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
image: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
sticker: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
video: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
interactive: {
action: {
name: '<string>',
button: '<string>',
buttons: [{type: 'reply', reply: {title: '<string>', id: '<string>'}}],
catalog_id: '<string>',
product_retailer_id: '<string>',
sections: [
{
product_items: [{product_retailer_id: '<string>'}],
rows: [{id: '<string>', title: '<string>', description: '<string>'}],
title: '<string>'
}
],
mode: '<string>',
parameters: {display_text: '<string>', url: '<string>'},
cards: [
{
card_index: 123,
type: 'cta_url',
header: {
image: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
video: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
}
},
body: JSON.stringify({text: '<string>'}),
action: {product_retailer_id: '<string>', catalog_id: '<string>'}
}
]
},
body: JSON.stringify({text: '<string>'}),
footer: {text: '<string>'},
header: {
document: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
image: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
video: {
link: 'http://example.com/media.jpg',
caption: '<string>',
filename: '<string>',
voice: true
},
text: '<string>',
sub_text: '<string>'
}
},
location: {
latitude: '<string>',
longitude: '<string>',
name: '<string>',
address: '<string>'
},
contacts: [
{
addresses: [
{
street: '<string>',
city: '<string>',
state: '<string>',
zip: '<string>',
country: '<string>',
country_code: '<string>',
type: '<string>'
}
],
birthday: '<string>',
emails: [{email: '<string>', type: '<string>'}],
name: '<string>',
org: {company: '<string>', department: '<string>', title: '<string>'},
phones: [{phone: '<string>', type: '<string>', wa_id: '<string>'}],
urls: [{url: '<string>', type: '<string>'}]
}
],
reaction: {message_id: '<string>', emoji: '<string>'},
biz_opaque_callback_data: '<string>',
template: {
template_id: '019cd44b-3a1c-781b-956e-bd33e9fd2ac6',
name: 'order_confirmation',
components: [{index: 123, parameters: [{text: '<string>'}]}]
}
},
type: 'WHATSAPP',
webhook_url: '<string>',
messaging_profile_id: '3c90c3cc-0d44-4b50-8888-8dd25736052a'
})
};
fetch('https://api.telnyx.com/v2/messages/whatsapp', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.telnyx.com/v2/messages/whatsapp",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'from' => '+13125551234',
'to' => '+13125551234',
'whatsapp_message' => [
'audio' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'document' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'image' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'sticker' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'video' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'interactive' => [
'action' => [
'name' => '<string>',
'button' => '<string>',
'buttons' => [
[
'type' => 'reply',
'reply' => [
'title' => '<string>',
'id' => '<string>'
]
]
],
'catalog_id' => '<string>',
'product_retailer_id' => '<string>',
'sections' => [
[
'product_items' => [
[
'product_retailer_id' => '<string>'
]
],
'rows' => [
[
'id' => '<string>',
'title' => '<string>',
'description' => '<string>'
]
],
'title' => '<string>'
]
],
'mode' => '<string>',
'parameters' => [
'display_text' => '<string>',
'url' => '<string>'
],
'cards' => [
[
'card_index' => 123,
'type' => 'cta_url',
'header' => [
'image' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'video' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
]
],
'body' => [
'text' => '<string>'
],
'action' => [
'product_retailer_id' => '<string>',
'catalog_id' => '<string>'
]
]
]
],
'body' => [
'text' => '<string>'
],
'footer' => [
'text' => '<string>'
],
'header' => [
'document' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'image' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'video' => [
'link' => 'http://example.com/media.jpg',
'caption' => '<string>',
'filename' => '<string>',
'voice' => true
],
'text' => '<string>',
'sub_text' => '<string>'
]
],
'location' => [
'latitude' => '<string>',
'longitude' => '<string>',
'name' => '<string>',
'address' => '<string>'
],
'contacts' => [
[
'addresses' => [
[
'street' => '<string>',
'city' => '<string>',
'state' => '<string>',
'zip' => '<string>',
'country' => '<string>',
'country_code' => '<string>',
'type' => '<string>'
]
],
'birthday' => '<string>',
'emails' => [
[
'email' => '<string>',
'type' => '<string>'
]
],
'name' => '<string>',
'org' => [
'company' => '<string>',
'department' => '<string>',
'title' => '<string>'
],
'phones' => [
[
'phone' => '<string>',
'type' => '<string>',
'wa_id' => '<string>'
]
],
'urls' => [
[
'url' => '<string>',
'type' => '<string>'
]
]
]
],
'reaction' => [
'message_id' => '<string>',
'emoji' => '<string>'
],
'biz_opaque_callback_data' => '<string>',
'template' => [
'template_id' => '019cd44b-3a1c-781b-956e-bd33e9fd2ac6',
'name' => 'order_confirmation',
'components' => [
[
'index' => 123,
'parameters' => [
[
'text' => '<string>'
]
]
]
]
]
],
'type' => 'WHATSAPP',
'webhook_url' => '<string>',
'messaging_profile_id' => '3c90c3cc-0d44-4b50-8888-8dd25736052a'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.telnyx.com/v2/messages/whatsapp"
payload := strings.NewReader("{\n \"from\": \"+13125551234\",\n \"to\": \"+13125551234\",\n \"whatsapp_message\": {\n \"audio\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"sticker\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"interactive\": {\n \"action\": {\n \"name\": \"<string>\",\n \"button\": \"<string>\",\n \"buttons\": [\n {\n \"type\": \"reply\",\n \"reply\": {\n \"title\": \"<string>\",\n \"id\": \"<string>\"\n }\n }\n ],\n \"catalog_id\": \"<string>\",\n \"product_retailer_id\": \"<string>\",\n \"sections\": [\n {\n \"product_items\": [\n {\n \"product_retailer_id\": \"<string>\"\n }\n ],\n \"rows\": [\n {\n \"id\": \"<string>\",\n \"title\": \"<string>\",\n \"description\": \"<string>\"\n }\n ],\n \"title\": \"<string>\"\n }\n ],\n \"mode\": \"<string>\",\n \"parameters\": {\n \"display_text\": \"<string>\",\n \"url\": \"<string>\"\n },\n \"cards\": [\n {\n \"card_index\": 123,\n \"type\": \"cta_url\",\n \"header\": {\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n }\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"action\": {\n \"product_retailer_id\": \"<string>\",\n \"catalog_id\": \"<string>\"\n }\n }\n ]\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"footer\": {\n \"text\": \"<string>\"\n },\n \"header\": {\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"text\": \"<string>\",\n \"sub_text\": \"<string>\"\n }\n },\n \"location\": {\n \"latitude\": \"<string>\",\n \"longitude\": \"<string>\",\n \"name\": \"<string>\",\n \"address\": \"<string>\"\n },\n \"contacts\": [\n {\n \"addresses\": [\n {\n \"street\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"zip\": \"<string>\",\n \"country\": \"<string>\",\n \"country_code\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"birthday\": \"<string>\",\n \"emails\": [\n {\n \"email\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"name\": \"<string>\",\n \"org\": {\n \"company\": \"<string>\",\n \"department\": \"<string>\",\n \"title\": \"<string>\"\n },\n \"phones\": [\n {\n \"phone\": \"<string>\",\n \"type\": \"<string>\",\n \"wa_id\": \"<string>\"\n }\n ],\n \"urls\": [\n {\n \"url\": \"<string>\",\n \"type\": \"<string>\"\n }\n ]\n }\n ],\n \"reaction\": {\n \"message_id\": \"<string>\",\n \"emoji\": \"<string>\"\n },\n \"biz_opaque_callback_data\": \"<string>\",\n \"template\": {\n \"template_id\": \"019cd44b-3a1c-781b-956e-bd33e9fd2ac6\",\n \"name\": \"order_confirmation\",\n \"components\": [\n {\n \"index\": 123,\n \"parameters\": [\n {\n \"text\": \"<string>\"\n }\n ]\n }\n ]\n }\n },\n \"type\": \"WHATSAPP\",\n \"webhook_url\": \"<string>\",\n \"messaging_profile_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.telnyx.com/v2/messages/whatsapp")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"from\": \"+13125551234\",\n \"to\": \"+13125551234\",\n \"whatsapp_message\": {\n \"audio\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"sticker\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"interactive\": {\n \"action\": {\n \"name\": \"<string>\",\n \"button\": \"<string>\",\n \"buttons\": [\n {\n \"type\": \"reply\",\n \"reply\": {\n \"title\": \"<string>\",\n \"id\": \"<string>\"\n }\n }\n ],\n \"catalog_id\": \"<string>\",\n \"product_retailer_id\": \"<string>\",\n \"sections\": [\n {\n \"product_items\": [\n {\n \"product_retailer_id\": \"<string>\"\n }\n ],\n \"rows\": [\n {\n \"id\": \"<string>\",\n \"title\": \"<string>\",\n \"description\": \"<string>\"\n }\n ],\n \"title\": \"<string>\"\n }\n ],\n \"mode\": \"<string>\",\n \"parameters\": {\n \"display_text\": \"<string>\",\n \"url\": \"<string>\"\n },\n \"cards\": [\n {\n \"card_index\": 123,\n \"type\": \"cta_url\",\n \"header\": {\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n }\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"action\": {\n \"product_retailer_id\": \"<string>\",\n \"catalog_id\": \"<string>\"\n }\n }\n ]\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"footer\": {\n \"text\": \"<string>\"\n },\n \"header\": {\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"text\": \"<string>\",\n \"sub_text\": \"<string>\"\n }\n },\n \"location\": {\n \"latitude\": \"<string>\",\n \"longitude\": \"<string>\",\n \"name\": \"<string>\",\n \"address\": \"<string>\"\n },\n \"contacts\": [\n {\n \"addresses\": [\n {\n \"street\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"zip\": \"<string>\",\n \"country\": \"<string>\",\n \"country_code\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"birthday\": \"<string>\",\n \"emails\": [\n {\n \"email\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"name\": \"<string>\",\n \"org\": {\n \"company\": \"<string>\",\n \"department\": \"<string>\",\n \"title\": \"<string>\"\n },\n \"phones\": [\n {\n \"phone\": \"<string>\",\n \"type\": \"<string>\",\n \"wa_id\": \"<string>\"\n }\n ],\n \"urls\": [\n {\n \"url\": \"<string>\",\n \"type\": \"<string>\"\n }\n ]\n }\n ],\n \"reaction\": {\n \"message_id\": \"<string>\",\n \"emoji\": \"<string>\"\n },\n \"biz_opaque_callback_data\": \"<string>\",\n \"template\": {\n \"template_id\": \"019cd44b-3a1c-781b-956e-bd33e9fd2ac6\",\n \"name\": \"order_confirmation\",\n \"components\": [\n {\n \"index\": 123,\n \"parameters\": [\n {\n \"text\": \"<string>\"\n }\n ]\n }\n ]\n }\n },\n \"type\": \"WHATSAPP\",\n \"webhook_url\": \"<string>\",\n \"messaging_profile_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.telnyx.com/v2/messages/whatsapp")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"from\": \"+13125551234\",\n \"to\": \"+13125551234\",\n \"whatsapp_message\": {\n \"audio\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"sticker\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"interactive\": {\n \"action\": {\n \"name\": \"<string>\",\n \"button\": \"<string>\",\n \"buttons\": [\n {\n \"type\": \"reply\",\n \"reply\": {\n \"title\": \"<string>\",\n \"id\": \"<string>\"\n }\n }\n ],\n \"catalog_id\": \"<string>\",\n \"product_retailer_id\": \"<string>\",\n \"sections\": [\n {\n \"product_items\": [\n {\n \"product_retailer_id\": \"<string>\"\n }\n ],\n \"rows\": [\n {\n \"id\": \"<string>\",\n \"title\": \"<string>\",\n \"description\": \"<string>\"\n }\n ],\n \"title\": \"<string>\"\n }\n ],\n \"mode\": \"<string>\",\n \"parameters\": {\n \"display_text\": \"<string>\",\n \"url\": \"<string>\"\n },\n \"cards\": [\n {\n \"card_index\": 123,\n \"type\": \"cta_url\",\n \"header\": {\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n }\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"action\": {\n \"product_retailer_id\": \"<string>\",\n \"catalog_id\": \"<string>\"\n }\n }\n ]\n },\n \"body\": {\n \"text\": \"<string>\"\n },\n \"footer\": {\n \"text\": \"<string>\"\n },\n \"header\": {\n \"document\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"image\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"video\": {\n \"link\": \"http://example.com/media.jpg\",\n \"caption\": \"<string>\",\n \"filename\": \"<string>\",\n \"voice\": true\n },\n \"text\": \"<string>\",\n \"sub_text\": \"<string>\"\n }\n },\n \"location\": {\n \"latitude\": \"<string>\",\n \"longitude\": \"<string>\",\n \"name\": \"<string>\",\n \"address\": \"<string>\"\n },\n \"contacts\": [\n {\n \"addresses\": [\n {\n \"street\": \"<string>\",\n \"city\": \"<string>\",\n \"state\": \"<string>\",\n \"zip\": \"<string>\",\n \"country\": \"<string>\",\n \"country_code\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"birthday\": \"<string>\",\n \"emails\": [\n {\n \"email\": \"<string>\",\n \"type\": \"<string>\"\n }\n ],\n \"name\": \"<string>\",\n \"org\": {\n \"company\": \"<string>\",\n \"department\": \"<string>\",\n \"title\": \"<string>\"\n },\n \"phones\": [\n {\n \"phone\": \"<string>\",\n \"type\": \"<string>\",\n \"wa_id\": \"<string>\"\n }\n ],\n \"urls\": [\n {\n \"url\": \"<string>\",\n \"type\": \"<string>\"\n }\n ]\n }\n ],\n \"reaction\": {\n \"message_id\": \"<string>\",\n \"emoji\": \"<string>\"\n },\n \"biz_opaque_callback_data\": \"<string>\",\n \"template\": {\n \"template_id\": \"019cd44b-3a1c-781b-956e-bd33e9fd2ac6\",\n \"name\": \"order_confirmation\",\n \"components\": [\n {\n \"index\": 123,\n \"parameters\": [\n {\n \"text\": \"<string>\"\n }\n ]\n }\n ]\n }\n },\n \"type\": \"WHATSAPP\",\n \"webhook_url\": \"<string>\",\n \"messaging_profile_id\": \"3c90c3cc-0d44-4b50-8888-8dd25736052a\"\n}"
response = http.request(request)
puts response.read_body{
"data": {
"record_type": "message",
"direction": "outbound",
"id": "4031938e-60e4-4235-a8dd-0b1c55a23e7a",
"type": "WHATSAPP",
"organization_id": "9f61d8e1-7687-4d6d-9cae-9ff682985983",
"messaging_profile_id": "4001781e-626f-4a41-a914-b1b682150f94",
"from": {
"phone_number": "<string>",
"carrier": "<string>"
},
"to": [
{
"phone_number": "+13125551234",
"status": "queued",
"carrier": "Verizon Wireless",
"line_type": "Wireless"
}
],
"body": {
"audio": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"sticker": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"interactive": {
"action": {
"name": "<string>",
"button": "<string>",
"buttons": [
{
"type": "reply",
"reply": {
"title": "<string>",
"id": "<string>"
}
}
],
"catalog_id": "<string>",
"product_retailer_id": "<string>",
"sections": [
{
"product_items": [
{
"product_retailer_id": "<string>"
}
],
"rows": [
{
"id": "<string>",
"title": "<string>",
"description": "<string>"
}
],
"title": "<string>"
}
],
"mode": "<string>",
"parameters": {
"display_text": "<string>",
"url": "<string>"
},
"cards": [
{
"card_index": 123,
"type": "cta_url",
"header": {
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
}
},
"body": {
"text": "<string>"
},
"action": {
"product_retailer_id": "<string>",
"catalog_id": "<string>"
}
}
]
},
"body": {
"text": "<string>"
},
"footer": {
"text": "<string>"
},
"header": {
"document": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"image": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"video": {
"link": "http://example.com/media.jpg",
"caption": "<string>",
"filename": "<string>",
"voice": true
},
"text": "<string>",
"sub_text": "<string>"
}
},
"location": {
"latitude": "<string>",
"longitude": "<string>",
"name": "<string>",
"address": "<string>"
},
"contacts": [
{
"addresses": [
{
"street": "<string>",
"city": "<string>",
"state": "<string>",
"zip": "<string>",
"country": "<string>",
"country_code": "<string>",
"type": "<string>"
}
],
"birthday": "<string>",
"emails": [
{
"email": "<string>",
"type": "<string>"
}
],
"name": "<string>",
"org": {
"company": "<string>",
"department": "<string>",
"title": "<string>"
},
"phones": [
{
"phone": "<string>",
"type": "<string>",
"wa_id": "<string>"
}
],
"urls": [
{
"url": "<string>",
"type": "<string>"
}
]
}
],
"reaction": {
"message_id": "<string>",
"emoji": "<string>"
},
"biz_opaque_callback_data": "<string>",
"text": {
"body": "Hello from Telnyx!",
"preview_url": false
},
"template": {
"template_id": "019cd44b-3a1c-781b-956e-bd33e9fd2ac6",
"name": "order_confirmation",
"language": {
"code": "en_US",
"policy": "deterministic"
},
"components": [
{
"index": 123,
"parameters": [
{
"text": "<string>"
}
]
}
]
}
},
"encoding": "utf-8",
"received_at": "2023-11-07T05:31:56Z",
"wait_seconds": 0.5
}
}{
"errors": [
{
"code": "<string>",
"title": "<string>",
"detail": "<string>",
"source": {
"pointer": "<string>",
"parameter": "<string>"
},
"meta": {}
}
]
}