Skip to content

REST API & webhooks

Base URL: https://your-host.example.com/api/v1

Dashboard endpoints under /api/* (without /v1) are private browser endpoints and are not part of this API. They require a session cookie and reject requests that do not come from the app’s own front end.

Create a key from Dashboard → API Access. The complete value is shown once and starts with wask_. Only a hash is stored, so a lost key must be regenerated rather than recovered.

Send it in every request:

X-API-Key: wask_your_api_key

A key can carry an expiry date, a total request budget, a per-minute rate limit, an active/inactive flag, and an IP allowlist (IPv4, IPv6, and CIDR ranges; an empty list means no restriction).

Success: { "success": true, "data": {}, "message": "…" }

Error: { "success": false, "error": { "code": "VALIDATION_ERROR", "message": "…" } }

Code Status Meaning
VALIDATION_ERROR 400 A field or uploaded file is invalid
UNAUTHORIZED 401 Key missing, invalid, expired, disabled, over budget, or from a disallowed address
NOT_FOUND 404 The job, campaign or template does not exist
CONFLICT 409 The requested state transition is not allowed
RATE_LIMITED 429 The key exceeded its per-minute rate
SERVICE_UNAVAILABLE 503 Immediate delivery was requested while WhatsApp was disconnected
INTERNAL_ERROR 500 An unexpected server or queue error

Two limits apply, and they are not the same thing:

  • Your key’s limit, configured per key.
  • WhatsApp’s tolerance, which is not negotiable. The send queue runs one message at a time at a maximum of 30 per minute with jitter. A campaign of 1,000 recipients takes at least half an hour.

Campaigns created through the API are capped at 5,000 recipients, default to randomised delays of 3–8 seconds between sends (delayMinSeconds / delayMaxSeconds), and are drafts unless queued. Campaign progress lists recipients paginated (recipientLimit default 200, max 1000). Telegram sends run on a separate queue (concurrency 3, 20/min).

Method Endpoint Purpose
GET /api/v1/session WhatsApp connection state
POST /api/v1/messages/send Queue an immediate text or media message
POST /api/v1/messages/schedule Queue a scheduled or recurring message
GET /api/v1/messages/:jobId Read job state
DELETE /api/v1/messages/:jobId Cancel a pending/scheduled job
PATCH /api/v1/messages/:jobId Edit a queued or delivered message
DELETE /api/v1/messages/:jobId/message Delete a delivered message for everyone
POST /api/v1/messages/poll Send a poll (2–12 options)
POST /api/v1/messages/interactive Buttons or a list menu
POST /api/v1/status Post a WhatsApp status
POST /api/v1/campaigns Create a campaign (draft by default)
POST /api/v1/campaigns/:id/queue Start a draft campaign
GET /api/v1/campaigns/:id Campaign progress (recipients paginated)
GET /api/v1/templates List API templates
POST /api/v1/templates/:id/send Render and queue a template
Terminal window
curl --request POST http://localhost:3000/api/v1/messages/send \
--header "X-API-Key: wask_your_key" \
--header "Content-Type: application/json" \
--data '{"to":"201001234567","message":"Hello from Leviro Relay"}'

Fields: to (required, international number or JID), message (required), type (default text), scheduleAt (ISO 8601), recurrence (daily, weekly, monthly, yearly). Media sends use multipart/form-data with media (50 MB maximum), type (image, video, audio, document), caption, and ptt for voice notes. A successful queue returns 201 with {jobId, status: "pending", scheduledAt, createdAt}.

Job states: pending, scheduled, processing, completed, failed, cancelled. Queuing success is not delivery — poll GET /messages/:jobId or subscribe to the message.sent / message.failed webhooks. The API has no idempotency key: retrying a request can queue the message twice.

Unauthenticated, for load balancers and container runtimes. They answer with booleans only — never a connection string, a driver message, or a version.

Method Endpoint 200 when
GET /health/live The process is running
GET /health/ready MongoDB and Redis both answer
GET /health/worker A worker sent a heartbeat in the last minute

Outbound only — Relay has no inbound webhook receiver. Create an endpoint from Dashboard → Webhooks, choose which events it wants, and store the signing secret shown once at creation.

Event Fires when
session.connected / session.disconnected / session.qr The WhatsApp socket came up / went down / a new QR is waiting (the payload contains no QR code)
message.sent / message.failed A queued message reached WhatsApp / failed after its last retry
message.delivered / message.read The recipient’s device acknowledged it / opened it
campaign.started / campaign.progress / campaign.completed A campaign was queued / one more recipient finished / every recipient reached a terminal state

Each delivery carries X-WA-Event, X-WA-Delivery, X-WA-Timestamp, and X-WA-Signature (sha256= HMAC over `${timestamp}.${rawBody}`). Verify it with crypto.timingSafeEqual and reject anything older than five minutes. Any 2xx is success; anything else (including a redirect, which is never followed) retries 6 times with exponential backoff from 5 seconds. A receiver that does not answer within 10 seconds is treated as down. An endpoint that fails 20 deliveries in a row is disabled automatically. Delivery is at-least-once — deduplicate on deliveryId. The destination must be a public address; private, loopback, and link-local addresses are refused.

A ready-made request collection is in the Relay repository at docs/Leviro_Relay_API.postman_collection.json.