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:

http
Authorization: Bearer gr8_live_xxxxxxxxxxxxxxxx

Keys belong to your workspace. Revoke a key immediately if it leaks.

Send a template message

bash
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

typeBody fieldsWhen
texttextInside the 24-hour window
image / video / audio / documentmedia_id, optional captionInside the 24-hour window; upload first with /api/v1/media/
interactiveinteractive object — quick-reply buttons or a link button (see below)Inside the 24-hour window
templatetemplate_name, variables, optional header / button valuesAny 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.

Quick-reply buttons
{
  "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" }]
  }
}
Link button
{
  "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.

EventSent when
message.receivedA customer sends you a message (including button taps).
message.statusAn outgoing message is sent, delivered, read or fails.
campaign.completedA campaign finishes sending.

Each delivery is a POST with a JSON body { "event", "organization_id", "data" } and these headers:

HeaderValue
X-Gr8chat-EventThe event name, e.g. message.status
X-Gr8chat-TimestampUnix time (seconds) when the delivery was signed
X-Gr8chat-Signaturesha256= 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.

Node.js (Express)
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);
});
Python (Flask)
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 "", 200

Reply 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

MethodPathPurpose
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:

json
{ "detail": "Insufficient wallet balance (₹0.00). Recharge to continue.", "code": "insufficient_balance" }
codeMeaning
kyc_requiredBusiness verification isn't approved yet
no_planNo active plan
insufficient_balanceWallet can't cover the message
window_closedFree-form message outside the 24-hour window — send a template
template_not_approvedTemplate is pending, rejected or paused
opted_outThe contact replied STOP
invalid_phone / invalid_inputCheck the request body
NextAccount, email and password

Still stuck? Talk to a person.

Email us with your workspace name and we'll get back to you.

info@thegr8labs.com