English
Send Message
POST/messageZawa's star endpoint. Send a message to a number, group, or channel, with seven types to choose from: text, image, video, audio, document, location, and contact. Each type needs different fields, so check the tables below.
Endpoint Details
- Base URL:
https://api-zawa.azickri.com - Headers:
id,session-id, andContent-Type: application/json - Requires: a connected session (
isConnected: true)
Headers
| Header | Type | Required | Description |
|---|---|---|---|
id | string | Yes | The id from Create Session. |
session-id | string | Yes | The sessionId from Create Session. |
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
phone | string | One of* | Recipient number in international format, e.g. 6281234567890. |
group | string | One of* | Group ID, e.g. [email protected]. |
newsletter | string | One of* | Channel ID, e.g. 120363000000000000@newsletter. |
type | string | Yes | Message type: text, image, video, audio, document, location, or contact. |
text | string | For text | The message text. For image, video, and document it becomes the caption (optional). |
image | object | For image | See the image object. |
video | object | For video | See the video object. |
audio | object | For audio | See the audio object. |
document | object | For document | See the document object. |
location | object | For location | See the location object. |
contact | object | For contact | See the contact object. |
* Fill in one of phone, group, or newsletter. If you fill in more than one, Zawa uses group first, then newsletter, then phone. The number format rules are in Core Concepts.
Media Objects
Media is sent by URL. Zawa downloads the file itself, so the URL must be public and point straight at the file. See also Sending Media From a URL.
| Object | Field | Type | Required | Description |
|---|---|---|---|---|
image | url | string | Yes | Image URL. JPG is the safest choice. |
mimetype | string | Yes | For example image/jpeg. | |
thumbnail | string | No | Thumbnail image URL. Uses the default thumbnail if empty. | |
video | url | string | Yes | Video URL. MP4 is the safest choice. |
mimetype | string | Yes | For example video/mp4. | |
duration | number | Yes | Video length in seconds, greater than 0. | |
thumbnail | string | No | Thumbnail image URL. Uses the default thumbnail if empty. | |
audio | url | string | Yes | Audio URL. MP3 is the safest choice. |
mimetype | string | Yes | For example audio/mpeg. | |
duration | number | Yes | Audio length in seconds, greater than 0. | |
document | url | string | Yes | Document URL. |
name | string | Yes | File name shown in the chat, e.g. invoice.pdf. | |
size | number | Yes | File size in bytes, greater than 0. | |
mimetype | string | Yes | For example application/pdf. |
Audio isn't a voice note
Audio is sent as a regular audio file, not as a voice note (the green waveform kind).
Location and Contact Objects
| Object | Field | Type | Required | Description |
|---|---|---|---|---|
location | latitude | number | Yes | Latitude, must not be 0. |
longitude | number | Yes | Longitude, must not be 0. | |
name | string | No | Place name, e.g. Monas. | |
address | string | No | Place address. | |
contact | name | string | Yes | Name of the shared contact. |
phone | string | Yes | The contact's number in international format, e.g. 6281234567890. |
Example Request
The simplest example: send a text message to one number.
bash
curl -X POST "https://api-zawa.azickri.com/message" \
-H "id: YOUR_ID" \
-H "session-id: YOUR_SESSION_ID" \
-H "Content-Type: application/json" \
-d '{"phone":"6281234567890","type":"text","text":"Hello from Zawa! 👋"}'javascript
import axios from 'axios';
const response = await axios.post(
'https://api-zawa.azickri.com/message',
{
phone: '6281234567890',
type: 'text',
text: 'Hello from Zawa! 👋',
},
{
headers: {
'id': 'YOUR_ID',
'session-id': 'YOUR_SESSION_ID',
},
},
);
console.log(response.data);javascript
const response = await fetch('https://api-zawa.azickri.com/message', {
method: 'POST',
headers: {
'id': 'YOUR_ID',
'session-id': 'YOUR_SESSION_ID',
'Content-Type': 'application/json',
},
body: JSON.stringify({
phone: '6281234567890',
type: 'text',
text: 'Hello from Zawa! 👋',
}),
});
const data = await response.json();
console.log(data);Body Examples by Type
Swap the body in the request above for any of these.
json
{
"phone": "6281234567890",
"type": "text",
"text": "Hello from Zawa! 👋"
}json
{
"phone": "6281234567890",
"type": "image",
"text": "This is the caption, it's optional",
"image": {
"url": "https://example.com/image.jpg",
"mimetype": "image/jpeg"
}
}json
{
"phone": "6281234567890",
"type": "video",
"text": "Video caption",
"video": {
"url": "https://example.com/video.mp4",
"mimetype": "video/mp4",
"duration": 30,
"thumbnail": "https://example.com/video-thumbnail.jpg"
}
}json
{
"phone": "6281234567890",
"type": "audio",
"audio": {
"url": "https://example.com/audio.mp3",
"mimetype": "audio/mpeg",
"duration": 30
}
}json
{
"phone": "6281234567890",
"type": "document",
"text": "Here's this month's invoice",
"document": {
"url": "https://example.com/invoice.pdf",
"name": "invoice.pdf",
"size": 102400,
"mimetype": "application/pdf"
}
}json
{
"phone": "6281234567890",
"type": "location",
"location": {
"name": "Monas",
"address": "Gambir, Central Jakarta",
"latitude": -6.175392,
"longitude": 106.827153
}
}json
{
"phone": "6281234567890",
"type": "contact",
"contact": {
"name": "Azickri",
"phone": "6281234567890"
}
}json
{
"group": "[email protected]",
"type": "text",
"text": "Hi everyone! 👋"
}json
{
"newsletter": "120363000000000000@newsletter",
"type": "text",
"text": "Fresh update coming through!"
}Response
json
{
"messageId": "3EB0C4A8F1D2B3E4A5F6"
}json
// No recipient
{
"statusCode": 400,
"message": "invalid phone, group or newsletter"
}
// A required field for that type is missing
{
"statusCode": 400,
"message": "image should not be empty"
}
// Missing headers
{
"statusCode": 400,
"message": "invalid header"
}json
{
"statusCode": 404,
"message": "session not found"
}json
// Session isn't connected
{
"statusCode": 500,
"message": "session not connected"
}
// Media download failed
{
"statusCode": 500,
"message": "error parser file from url 404 Not Found"
}| Field | Type | Description |
|---|---|---|
messageId | string | The message ID from WhatsApp. |
A messageId doesn't guarantee delivery
A messageId means WhatsApp's server accepted the message. Zawa doesn't check whether the recipient is on WhatsApp, so make sure the number is right.