Developer API
Send messages, manage contacts and upload media with the Gr8chat REST API.
6 min read
Access and authentication
API access unlocks once your business verification is approved. Create a key in Developers → API keys — the full key is shown only once, so store it securely. Send it as a bearer token:
Authorization: Bearer gr8_live_xxxxxxxxxxxxxxxxKeys belong to your workspace. Revoke a key immediately if it leaks.
Send a template message
curl -X POST https://YOUR-GR8CHAT-DOMAIN/api/v1/messages/ \
-H "Authorization: Bearer gr8_live_..." \
-H "Content-Type: application/json" \
-d '{
"to": "+919876543210",
"type": "template",
"template_name": "order_shipped",
"language": "en",
"variables": ["Asha", "#1042"],
"header_variables": ["#1042"],
"button_variables": ["1042"]
}'The response includes the message id and status. Check delivery later with GET /api/v1/messages/{id}/.
Other message types
| type | Body fields | When |
|---|---|---|
| text | text | Inside the 24-hour window |
| image / video / audio / document | media_id, optional caption | Inside the 24-hour window; upload first with /api/v1/media/ |
| interactive | interactive object — quick-reply buttons or a link button (see below) | Inside the 24-hour window |
| template | template_name, variables, optional header / button values | Any time |
Interactive messages
Inside the 24-hour window you can send messages with buttons. Use type: "interactive" with either up to three quick-reply buttons, or one call-to-action link button. Button titles and link text are limited to 20 characters; header and footer are optional.
{
"to": "+919876543210",
"type": "interactive",
"interactive": {
"type": "buttons",
"body": "How can we help with order #1042?",
"buttons": [{ "title": "Track order" }, { "title": "Return item" }, { "title": "Talk to us" }]
}
}{
"to": "+919876543210",
"type": "interactive",
"interactive": {
"type": "cta_url",
"body": "Your invoice is ready.",
"display_text": "View invoice",
"url": "https://example.com/invoices/1042"
}
}When a customer taps a quick-reply button, the reply arrives in your inbox (and as a message.received webhook) with the button title as its text. Outside the window, use a template with buttons instead and pass button_variables for dynamic URL buttons.
Webhooks
Get events pushed to your server instead of polling. Set it up in Developers → Webhooks: enter a public https:// URL, pick the events, and copy the signing secret. Webhooks are available to verified workspaces only; private, localhost and internal addresses are rejected, and redirects aren't followed. Use Send test to check your endpoint.
| Event | Sent when |
|---|---|
| message.received | A customer sends you a message (including button taps). |
| message.status | An outgoing message is sent, delivered, read or fails. |
| campaign.completed | A campaign finishes sending. |
Each delivery is a POST with a JSON body { "event", "organization_id", "data" } and these headers:
| Header | Value |
|---|---|
| X-Gr8chat-Event | The event name, e.g. message.status |
| X-Gr8chat-Timestamp | Unix time (seconds) when the delivery was signed |
| X-Gr8chat-Signature | sha256= followed by the hex HMAC-SHA256 of timestamp + "." + raw body, keyed with your secret |
Always verify the signature against the raw request body before parsing it, compare in constant time, and reject old timestamps (for example older than 5 minutes) to block replays. Rotate the secret from the Webhooks page if it leaks.
import crypto from "node:crypto";
import express from "express";
const app = express();
const SECRET = process.env.GR8CHAT_WEBHOOK_SECRET;
app.post("/gr8chat/webhook", express.raw({ type: "application/json" }), (req, res) => {
const ts = req.get("X-Gr8chat-Timestamp") ?? "";
const sig = req.get("X-Gr8chat-Signature") ?? "";
const expected = "sha256=" + crypto.createHmac("sha256", SECRET).update(ts + "." + req.body).digest("hex");
const fresh = Math.abs(Date.now() / 1000 - Number(ts)) < 300;
const valid = sig.length === expected.length && crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected));
if (!fresh || !valid) return res.sendStatus(401);
const { event, data } = JSON.parse(req.body.toString("utf8"));
// handle event…
res.sendStatus(200);
});import hashlib, hmac, json, os, time
from flask import Flask, abort, request
app = Flask(__name__)
SECRET = os.environ["GR8CHAT_WEBHOOK_SECRET"].encode()
@app.post("/gr8chat/webhook")
def gr8chat_webhook():
ts = request.headers.get("X-Gr8chat-Timestamp", "")
sig = request.headers.get("X-Gr8chat-Signature", "")
raw = request.get_data() # raw bytes, before any JSON parsing
expected = "sha256=" + hmac.new(SECRET, ts.encode() + b"." + raw, hashlib.sha256).hexdigest()
if not ts.isdigit() or abs(time.time() - int(ts)) > 300 or not hmac.compare_digest(sig, expected):
abort(401)
payload = json.loads(raw)
# handle payload["event"], payload["data"]…
return "", 200Reply with any 2xx status within a few seconds and do slow work in the background. Network errors, 5xx and 429 responses are retried with increasing delays (up to 5 attempts), so make your handler idempotent — the same event can arrive more than once.
Endpoints
| Method | Path | Purpose |
|---|---|---|
| POST | /api/v1/messages/ | Send a message |
| GET | /api/v1/messages/{id}/ | Message status |
| POST | /api/v1/contacts/ | Create or update a contact by phone |
| GET | /api/v1/templates/ | List approved templates and their variables |
| POST | /api/v1/media/ | Upload a file (multipart field file) |
Limits and errors
Each key can make up to 600 requests per minute. Errors return JSON with a human-readable detail and a machine-readable code:
{ "detail": "Insufficient wallet balance (₹0.00). Recharge to continue.", "code": "insufficient_balance" }| code | Meaning |
|---|---|
| kyc_required | Business verification isn't approved yet |
| no_plan | No active plan |
| insufficient_balance | Wallet can't cover the message |
| window_closed | Free-form message outside the 24-hour window — send a template |
| template_not_approved | Template is pending, rejected or paused |
| opted_out | The contact replied STOP |
| invalid_phone / invalid_input | Check the request body |