REST API reference for Relay - By Deewan: send SMS and WhatsApp messages, manage contacts, segments and campaigns, and read delivery logs. 77 endpoints, authenticated with a single API key. This page is public — no account needed to read it.
Two hosts, one API key
Generate a REST API key in the portal, then send it as
Authorization: Bearer <key> or X-API-Key. One key works
for both hosts. Which host serves a request is decided entirely by its path:
GW
Messaging — send SMS and WhatsApp, read and write contact tags and
CDP attributes. Every path under /api/v1/. https://ops.relay.deewan.sa
CP
Management API — contacts, segments, campaigns, message logs, apps
and billing reads. Every path under /api/mgmt/v1/. A key must have
Management API access enabled, which is a per-key setting in the portal. https://portal.relay.deewan.sa
The messaging host sends no CORS headers, so those endpoints are server-to-server
only — they cannot be called from a browser.
Platform
A connectivity check for the sending platform, for uptime monitoring.
- Needs no authentication. Every other endpoint needs a credential (see Authentication).
GET/api/healthMessaging host
Platform health check
Reports whether the platform is up and connected to its database (db) and its message queue (nats).
No authentication required.
Always answers 200 while the service runs; check db and nats for connected / disconnected.
cURL
curl -X GET "https://ops.relay.deewan.sa/api/health" \
-H "Content-Type: application/json"
JavaScript
const res = await fetch("https://ops.relay.deewan.sa/api/health", {
method: "GET",
headers: {
"Content-Type": "application/json"
},
});
const data = await res.json();
console.log(data);
Your contact list (CRM): create, search, import, export, update and delete contacts.
- The /api/v1/contacts/:phone endpoints read and update a contact's tags and custom attributes with an API key, by phone number.
GET/api/mgmt/v1/contactsManagement hostAPI key
List contacts
A page of contacts, newest first, narrowed by status, opt-in status, segment, tag and a search query.
search takes plain text (matched against name, phone, email, tags and custom attributes) or comma-separated conditions such as tier = gold, country = SA, vip; all terms must match.
A query is limited to 512 characters and 12 terms. An unparseable condition returns 400 invalid_query.
A search that takes too long returns 503 query_too_slow — add an exact tag or status to narrow it.
Engagement figures in behaviorProfile cover the last 30 days and are recalculated nightly.
Parameters
Name
In
Type
Description
page
query
integer
Page number (default 1) 1
limit
query
integer
Items per page, max 200 (default 50) 50
status
query
string
subscribed or unsubscribedsubscribed
optInStatus
query
string
confirmed, pending or not-requestedconfirmed
tag
query
string
Only contacts with this tag vip
segment
query
string
Only contacts in this segment (ObjectId) 64f1...
search
query
string
Free text, or conditions such as tier = gold, vip (see above). q is accepted as an alias. jane
Creates one contact. Requires the admin or editor role.
A contact needs a valid phone or email. The phone is converted to international format; a number without a country code uses defaultCountry, else your account's default country.
A phone already used by another contact returns 409; so does the email of an email-only contact that already exists.
On the Free plan, a contact beyond your included contacts is refused with 403 free_contact_cap.
Request body
Field
Type
Required
Description
phone
string
one of
Mobile number, ideally in international format (+9665…). Rejected with 400 if it is not a valid number.
email
string
one of
Email address. Send it alone for an email-only contact.
name
string
optional
Display name.
status
string
optional
subscribed (default) or unsubscribed. Creating as unsubscribed records the opt-out date.
optInStatus
string
optional
confirmed, pending or not-requested (default).
tags
string[]
optional
Tags to add to the contact.
country
string
optional
Country, stored as given. city and region work the same way.
metadata.cdpAttributes
object
optional
Custom attributes as key/value pairs, e.g. { "tier": "gold" }.
defaultCountry
string
optional
Dialling code for a number without a country code: 966, 971, 973, 974, 965, 968, 962 or 20.
Adds many contacts in one request. Contacts that already exist are skipped, not updated. Requires the admin or editor role.
Up to 100,000 contacts per request (413 above that).
Each row needs a valid phone or email; rows with neither are counted in invalid. Rows that repeat a phone or email in the same request are counted in duplicatesInFile.
A row with phone and email whose email belongs to an existing email-only contact adds the phone to that contact.
The response also reports emailOnly (email-only rows) and conflicts (rows lost to a simultaneous write).
addToSegment puts every contact in the request, new and existing, into a fixed segment. It is checked before any contact is written.
If adding to the segment fails afterwards, the import still stands and segmentError explains.
On the Free plan, an import that would exceed your included contacts is refused with 403 free_contact_cap.
Request body
Field
Type
Required
Description
contacts
object[]
required
The contacts to add (at least one).
contacts[].phone
string
one of
Mobile number. One without a country code uses defaultCountry.
contacts[].email
string
one of
Email address. Send it alone for an email-only contact.
contacts[].name
string
optional
Display name.
contacts[].status
string
optional
subscribed (default) or unsubscribed.
contacts[].tags
string[]
optional
Tags for the new contact.
defaultCountry
string
optional
Dialling code for numbers without a country code, e.g. 966. Default: your account's default country.
addToSegment
object
optional
Fixed segment to put the contacts in. Send segmentId or name, not both.
addToSegment.segmentId
string
one of
An existing fixed segment. A live segment is refused with 400.
addToSegment.name
string
one of
Name for a new fixed segment. 409 if a segment with that name exists.
Group contacts for campaign and automation targeting.
- A live segment (type: "dynamic") stores a rule; its members are whoever matches the rule when it is read. - A fixed segment (type: "static") holds a list of contacts that only changes when you add or remove them.
GET/api/mgmt/v1/segmentsManagement hostAPI key
List segments
Returns all segments, newest first.
A live segment's contactCount is recounted on each call; if a count is slow, the last known count is returned.
definition describes a live segment's rule in words. system: true marks segments Relay maintains from order data (they cannot be deleted).
Creates a live segment from a rule, or a fixed segment from the contacts matching a rule now and/or a list of contact ids. Requires the admin or editor role.
A rule is query and/or the status, optInStatus, tag and segment filters.
With a rule and membership other than "fixed", the rule is saved and re-evaluated on every read.
With membership: "fixed", up to 50,000 contacts matching the rule now are saved; truncated: true reports a cut-off. contactIds are added too.
With neither a rule nor contactIds, an empty fixed segment is created.
A live rule's segment filter must point at a fixed segment (400 otherwise).
Names are unique per account, ignoring case (409 if taken).
Snapshotting a slow rule returns 503 query_too_slow.
Request body
Field
Type
Required
Description
name
string
required
Segment name.
description
string
optional
Free-text description.
membership
string
optional
live (default) or fixed.
query
string
optional
Contact search query, e.g. city = Riyadh, vip — same syntax as search in List contacts.
status
string
optional
Rule filter: subscribed or unsubscribed.
optInStatus
string
optional
Rule filter: confirmed, pending or not-requested.
tag
string
optional
Rule filter: contacts with this tag.
segment
string
optional
Rule filter: contacts in this segment (ObjectId).
contactIds
string[]
optional
Contact ObjectIds to add, 1–5,000. Only with membership: "fixed".
Create, schedule and send broadcast campaigns to contact segments or to your own uploaded list of recipients.
- A campaign is created as a draft, gets its audience (segments, or a recipient file in three upload calls), then is launched. - Creating, editing, uploading, launching and pausing require the admin or editor role.
GET/api/mgmt/v1/campaignsManagement hostAPI key
List campaigns
Your campaigns, newest first, one page at a time, with an optional status filter.
Creates a campaign in draft status. Target contacts with targetSegments, or leave it out and attach your own recipient file with the three upload calls below. Then call Launch a campaign.
For SMS, send either free text in content or an approved SMS template in smsTemplateId — the campaign then sends the template's approved text.
Template tokens are filled from the recipient's value of the same name (a contact field or attribute, or a column of your recipient file), or from smsVariableMap.
A/B variants may each name their own smsTemplateId. The template must still be approved at launch, and must allow the campaign's sender if it restricts senders.
The sender must be one your account may use; otherwise the call returns 400.
A/B tests, tracked links and the WhatsApp and email settings take further fields, set by the campaign builder in the portal.
Request body
Field
Type
Required
Description
name
string
required
Campaign name, up to 120 characters, no HTML (<>).
channel
string
optional
sms (default), whatsapp or email.
senderId
string
conditional
SMS sender ID. Required for SMS campaigns.
content
string
one of
SMS text. In free text, {name} is the contact's name; with a recipient file, each of its variables is a {token}. Replaced by the template text when smsTemplateId is set.
smsTemplateId
string
one of
An SMS template of your account, used instead of content. Must be approved by launch time.
smsTemplateLocale
string
optional
Language version of the template, e.g. ar. Must exist on the template.
smsVariableMap
object
optional
Template token → value: another field's name ("code": "tier"), or a fixed value in quotes ("date": "\"30 Nov\"").
targetSegments
string[]
optional
Segment ids to send to. Leave out to upload a recipient file instead.
schedule
object
optional
When to send. Default: as soon as it is launched.
schedule.type
string
optional
immediate (default) or scheduled.
schedule.date
string
conditional
ISO 8601 date-time in the future. Required when type is scheduled.
schedule.timezone
string
optional
Time zone of the schedule (default UTC).
Free text
{
"name": "Summer Sale",
"senderId": "BRAND",
"content": "Hi {name}, get 20% off today! Reply STOP to unsubscribe.",
"targetSegments": [
"seg-id"
],
"schedule": {
"type": "immediate"
}
}
Step 1 of 3 for sending a campaign to your own list of recipients. Declare how many batches you will send and keep the returned uploadId for steps 2 and 3.
The campaign must be a draft, or scheduled and not yet started.
Starting a new upload discards any earlier upload that was never committed. The current audience stays in place until you commit.
Step 3 of 3. Once every declared batch has arrived, makes the upload the campaign's audience in one step, replacing any earlier file or segment targeting. Then call Launch a campaign.
If batches are missing, nothing is applied and the campaign keeps its previous audience.
Safe to retry: a repeated commit of the same upload returns the same total.
Parameters
Name
In
Type
Description
id *
path
string
Campaign id 64f1...
uploadId *
path
string
The id returned by the start call 7c9e6679-7425-40de-944b-e07fc1f90ae7
Send SMS one at a time, in batches of up to 1,000, or as a CSV file of up to 250,000 rows. Query, filter and export the delivery log.
- Sending endpoints use an API key; the delivery-log endpoints use a portal session. - The two run on different hosts — check the base URL on each endpoint.
GET/api/mgmt/v1/sendersManagement hostAPI key
Get available sender IDs
Returns the approved sender IDs you can send from.
Inside a project, only the sender IDs granted to that project are listed.
Sends one SMS. All checks (sender, balance, limits, routing) run before the answer, so 202 means the message is queued.
A rejected message answers 422 with the reason.
promotional messages inside the recipient's quiet hours are held and sent when the window opens.
Request body
Field
Type
Required
Description
from
string
required
An approved sender ID on your account.
to
string
required
Destination number in international format (+9665…).
text
string
required
The message text.
campaignId
string
optional
Links the message log to one of your campaigns.
messageIntent
string
optional
promotional or transactional. Default: the classification of your sender ID, else transactional. Only promotional messages wait for quiet hours to end.
curl -X POST "https://ops.relay.deewan.sa/api/v1/sms/messages/bulk" \
-H "Authorization: Bearer <api_key>" \
-H "Content-Type: application/json" \
-d '{"from":"BRAND","text":"Hi {name}, your order {orderId} is ready for pickup!","recipients":[{"to":"+12025551001","variables":{"name":"Alice","orderId":"A-123"}},{"to":"+12025551002","variables":{"name":"Bob","orderId":"B-456"}},{"to":"+12025551003"}],"campaignId":"64f1..."}'
Same Idempotency-Key as an earlier call — that job is returned
{
"jobId": "6727b1…",
"status": "sending"
}
400
Invalid settings, missing file, missing Idempotency-Key or an unacceptable fileUrl
{
"error": "An Idempotency-Key header (1–128 printable characters) is required, so a retried upload never creates a second job.",
"code": "idempotency_key_required"
}
401
No API key, or the Authorization header is not Bearer <key> — answered before the file is read
{
"error": "The Authorization header must be \"Bearer <key>\" (the word Bearer, a space, then the key) — or send the key in X-API-Key."
}
403
SMS is not enabled on your account
{
"error": "SMS is not enabled on your account. Contact your account manager to enable it.",
"code": "channel_disabled"
}
403
Sender not approved / IP not allowed
{
"error": "Sender ID \"BRAND\" is not in the approved senders list for this account"
}
413
File over 100 MB — refused at once when the request declares its size, otherwise as soon as 100 MB is passed
{
"error": "The file is larger than 100 MB. Split it into several jobs, or send it as fileUrl.",
"code": "file_too_large"
}
422
The uploaded file cannot be used (no phone column, empty, no valid numbers, not CSV) — answered as soon as the problem is found. The job is recorded as failed under jobId, so the Idempotency-Key is spent: fix the file and send it with a new key
{
"error": "No phone column found — name it one of: msisdn, to, mobile, phone.",
"code": "invalid_file",
"jobId": "6727b1…"
}
429
Too many jobs at once (3 being read or sent, 10 scheduled)
{
"error": "You already have 3 jobs being read or sent. Wait for one to finish."
}
GET/api/v1/sms/jobs/:idMessaging hostAPI key
Get a send job
Status, row counts, cost and delivery progress of a send job.
Normal path: validating (file being read) → ready (held, autoStart: false) or scheduled (sendAt) → queued → sending → completed.
failed: the file could not be used — see statusReason.
insufficient_balance: top up, then call Start or resume a send job.
stopped: a daily or project limit was reached — start again once it allows. A job stopped part-way resumes after the last message sent.
cancelled: stopped by Cancel a send job.
GET /api/v1/sms/jobs lists your jobs, newest first. Query: limit (1–100, default 25), status, and before = the next value of the previous page.
{
"note": "Returns text/csv — use in a download link or curl -o export.csv"
}
WhatsApp
Send WhatsApp messages from your registered numbers: approved templates, text replies and media (image, document, audio, video, sticker). All three use the same endpoint, chosen by type.
- Templates can be sent at any time. Text and media need an open 24-hour service window: the contact messaged you in the last 24 hours. - Contacts on your WhatsApp suppression list are refused (422, code suppressed).
Sends an approved message template. Templates are the only messages allowed when the contact has no open 24-hour service window.
Send an Idempotency-Key header so a retry never sends twice: the same key returns the earlier messageId with deduplicated: true.
A template that Relay knows is not approved in that language is refused with 422 before sending.
Use Get message status with the returned messageId to follow delivery.
Request body
Field
Type
Required
Description
from
string
required
Your registered WhatsApp number, in international format (with or without +, or 00), or its phone number ID. phoneNumberId is accepted as another name for this field.
to
string
required
Destination number in international format.
type
string
required
template.
template
object
required
The template to send.
template.name
string
required
Name of an approved template on the sending number's WhatsApp Business account.
template.language
string
required
Language code the template is approved in, e.g. en, ar.
template.variables
object
optional
Values for {{1}}, {{2}}, … keyed by number. Body placeholders are filled first, then URL-button placeholders in button order.
template.components
array
optional
Advanced: the components array in WhatsApp Cloud API format, sent as is. Used instead of variables when both are given.
replyToWamid
string
optional
The wamid of an earlier message to reply to.
clientRef
string
optional
Your own reference, stored on the message and returned by Get message status. Ignored when an Idempotency-Key header is sent.
Sends free-form text to a contact who messaged you in the last 24 hours (open service window).
Outside the window the send is refused with 409 (service_window_closed) — send a template instead.
Idempotency-Key works as for Send a template.
Request body
Field
Type
Required
Description
from
string
required
Your registered WhatsApp number or its phone number ID, as for Send a template.
to
string
required
Destination number in international format.
type
string
required
text.
text
object
required
The message.
text.body
string
required
Message text. WhatsApp allows up to 4,096 characters.
text.preview_url
boolean
optional
true shows a preview of the first link in the text.
replyToWamid
string
optional
The wamid of an earlier message (e.g. the contact's inbound message) to reply to.
clientRef
string
optional
Your own reference, returned by Get message status.
{
"from": "+31644102243",
"to": "+12025551234",
"type": "text",
"text": {
"body": "Thanks for reaching out — your order will ship today.",
"preview_url": false
},
"replyToWamid": "wamid.HBgL…"
}
cURL
curl -X POST "https://ops.relay.deewan.sa/api/v1/whatsapp/messages" \
-H "Authorization: Bearer <api_key>" \
-H "Content-Type: application/json" \
-d '{"from":"+31644102243","to":"+12025551234","type":"text","text":{"body":"Thanks for reaching out — your order will ship today.","preview_url":false},"replyToWamid":"wamid.HBgL…"}'
JavaScript
const res = await fetch("https://ops.relay.deewan.sa/api/v1/whatsapp/messages", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer <api_key>"
},
body: JSON.stringify({
"from": "+31644102243",
"to": "+12025551234",
"type": "text",
"text": {
"body": "Thanks for reaching out — your order will ship today.",
"preview_url": false
},
"replyToWamid": "wamid.HBgL…"
}),
});
const data = await res.json();
console.log(data);
Responses
202
Queued
{
"messageId": "wa_…",
"status": "queued"
}
409
Service window closed
{
"error": "No open 24h service window for this contact — use a template send instead",
"code": "service_window_closed"
}
Sends an image, document, audio, video or sticker to a contact who messaged you in the last 24 hours (open service window).
Set type and put the media under the key of the same name ("type": "document" → document: { … }).
Give either link or id; id wins if both are sent.
Captions are not shown for audio and sticker.
Outside the window the send is refused with 409 (service_window_closed).
Request body
Field
Type
Required
Description
from
string
required
Your registered WhatsApp number or its phone number ID, as for Send a template.
to
string
required
Destination number in international format.
type
string
required
image, document, audio, video or sticker.
image
object
conditional
The image, with type: "image".
image.link
string
one of
Public HTTPS URL WhatsApp downloads the file from.
image.id
string
one of
A WhatsApp media ID from an earlier upload.
image.caption
string
optional
Text shown under the image (also for video and document).
document
object
conditional
With type: "document": the same fields as image, plus filename.
document.filename
string
optional
File name shown to the contact.
video
object
conditional
With type: "video": link or id, and an optional caption.
audio
object
conditional
With type: "audio": link or id.
sticker
object
conditional
With type: "sticker": link or id.
replyToWamid
string
optional
The wamid of an earlier message to reply to.
clientRef
string
optional
Your own reference, returned by Get message status.
Image
{
"from": "+31644102243",
"to": "+12025551234",
"type": "image",
"image": {
"link": "https://cdn.example.com/orders/abc.jpg",
"caption": "Your order is on its way!"
}
}
curl -X POST "https://ops.relay.deewan.sa/api/v1/whatsapp/messages" \
-H "Authorization: Bearer <api_key>" \
-H "Content-Type: application/json" \
-d '{"from":"+31644102243","to":"+12025551234","type":"image","image":{"link":"https://cdn.example.com/orders/abc.jpg","caption":"Your order is on its way!"}}'
JavaScript
const res = await fetch("https://ops.relay.deewan.sa/api/v1/whatsapp/messages", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer <api_key>"
},
body: JSON.stringify({
"from": "+31644102243",
"to": "+12025551234",
"type": "image",
"image": {
"link": "https://cdn.example.com/orders/abc.jpg",
"caption": "Your order is on its way!"
}
}),
});
const data = await res.json();
console.log(data);
Responses
202
Queued
{
"messageId": "wa_…",
"status": "queued"
}
400
Media reference missing
{
"error": "image requires either `image.link` (public HTTPS URL) or `image.id` (Meta media id)"
}
Send email from your verified sender identities — a Relay address, or your own DKIM-verified domain.
- Delivery, bounce, complaint, open and click events update the message record and fire your webhooks. - Addresses on your suppression list (unsubscribed, bounced, complained) are refused.
POST/api/v1/email/messagesMessaging hostAPI key
Send using a template
Queues an email built from one of your approved email templates. Tokens in the subject and body are filled from variables and the recipient's contact.
If the address belongs to one of your contacts, its name, first_name, phone, country and attributes fill tokens automatically; variables override them.
The unsubscribe footer and List-Unsubscribe headers are added automatically.
Send an Idempotency-Key header (or clientRef): a repeat returns the first messageId without sending again.
Request body
Field
Type
Required
Description
to
string
required
Recipient email address.
from
string | object
optional
A full address ("Brand <hello@yourdomain.com>") or { identityId, address?, name? }. Leave out to use your default sender. The address must be one the sender identity allows.
from.identityId
string
optional
A sender identity _id from List sender identities.
from.address
string
optional
From address. Default: the identity's default From.
from.name
string
optional
Display name. Default: the identity's display name.
replyTo
string
optional
Reply-to address. Default: the identity's reply-to.
toName
string
optional
Recipient display name (up to 200 characters).
clientRef
string
optional
Your own reference. Also makes retries safe, like the Idempotency-Key header.
templateId
string
one of
An approved email template. Send this, or subject with html / text.
locale
string
optional
Language version of the template, e.g. ar. Unknown versions fall back to the template's default.
variables
object
optional
Token values for the subject and body. Keys are letters, digits and _; values are text, numbers or true/false.
{
"error": "Missing API key (Authorization: Bearer <key> or X-API-Key header)"
}
403
Email is not enabled on your account
{
"error": "Email is not enabled on your account. Contact your account manager to enable it.",
"code": "channel_disabled"
}
403
From address not allowed for that sender
{
"error": "From address news@other.com is not allowed for this sender",
"code": "from_not_allowed"
}
404
No matching sender identity
{
"error": "No sender identity matches `from`. Set one up under Channels → Email → Sender setup.",
"code": "sender_not_found"
}
409
Sender domain not verified
{
"error": "Sender domain mail.example.com is not verified",
"code": "sender_not_verified"
}
422
Suppressed recipient or unapproved template
{
"error": "Recipient is on the email suppression list",
"code": "suppressed",
"reason": "bounce"
}
429
TPS cap reached (per channel)
{
"error": "TPS cap of 50 msg/s reached",
"code": "throughput_exceeded"
}
503
Email not configured on this deployment
{
"error": "Email sending is not configured on this deployment",
"code": "email_not_configured"
}
POST/api/v1/email/messagesMessaging hostAPI key
Send raw HTML
Queues an email from HTML you supply, instead of a template.
Requires a verified own domain — not allowed from a shared Relay address.
The HTML is sanitised: scripts, iframes and forms are removed.
An unsubscribe footer is added when the HTML has no {unsubscribe_url}.
html and text together must stay under 9 MB.
Sent as transactional unless marketing is true.
Request body
Field
Type
Required
Description
to
string
required
Recipient email address.
from
string | object
optional
A full address ("Brand <hello@yourdomain.com>") or { identityId, address?, name? }. Leave out to use your default sender. The address must be one the sender identity allows.
from.identityId
string
optional
A sender identity _id from List sender identities.
from.address
string
optional
From address. Default: the identity's default From.
from.name
string
optional
Display name. Default: the identity's display name.
replyTo
string
optional
Reply-to address. Default: the identity's reply-to.
toName
string
optional
Recipient display name (up to 200 characters).
clientRef
string
optional
Your own reference. Also makes retries safe, like the Idempotency-Key header.
subject
string
one of
Subject line (up to 300 characters). Send with html and/or text, instead of templateId.
html
string
conditional
HTML body. At least one of html / text is required with subject.
text
string
conditional
Plain-text body.
marketing
boolean
optional
true treats a raw send as promotional: quiet hours, frequency caps and the CRM unsubscribe then apply. Default: transactional.
{
"from": "Brand <hello@mail.yourcompany.com>",
"to": "omar@example.com",
"subject": "Your order SA-10233 has shipped",
"html": "<p>Hi Omar, your order is on its way.</p><p><a href=\"{unsubscribe_url}\">Unsubscribe</a></p>",
"text": "Hi Omar, your order is on its way."
}
cURL
curl -X POST "https://ops.relay.deewan.sa/api/v1/email/messages" \
-H "Authorization: Bearer <api_key>" \
-H "Content-Type: application/json" \
-d '{"from":"Brand <hello@mail.yourcompany.com>","to":"omar@example.com","subject":"Your order SA-10233 has shipped","html":"<p>Hi Omar, your order is on its way.</p><p><a href=\"{unsubscribe_url}\">Unsubscribe</a></p>","text":"Hi Omar, your order is on its way."}'
JavaScript
const res = await fetch("https://ops.relay.deewan.sa/api/v1/email/messages", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer <api_key>"
},
body: JSON.stringify({
"from": "Brand <hello@mail.yourcompany.com>",
"to": "omar@example.com",
"subject": "Your order SA-10233 has shipped",
"html": "<p>Hi Omar, your order is on its way.</p><p><a href=\"{unsubscribe_url}\">Unsubscribe</a></p>",
"text": "Hi Omar, your order is on its way."
}),
});
const data = await res.json();
console.log(data);
{
"error": "Raw HTML sends require a verified own domain; use a template with a Relay address",
"code": "raw_requires_domain"
}
413
Body too large
{
"error": "Email body exceeds 9 MB"
}
POST/api/v1/email/messagesMessaging hostAPI key
Send with attachments
Add attachments to either kind of send (template or raw HTML) to deliver files with the email — invoices, tickets, statements.
Requires a verified own domain.
Up to 10 files, 10 MB in total before encoding.
Allowed types, by extension: pdf, png, jpg/jpeg, gif, webp, docx, xlsx, pptx, odt, ods, csv, txt, ics, json, xml. Archives, macro-enabled or legacy Office files and programs are refused.
Each file's content must match its extension, so a renamed program is refused.
Files are kept only until the email is sent. Get message status lists their name, type and size.
Request body
Field
Type
Required
Description
to
string
required
Recipient email address.
from
string | object
optional
A full address ("Brand <hello@yourdomain.com>") or { identityId, address?, name? }. Leave out to use your default sender. The address must be one the sender identity allows.
from.identityId
string
optional
A sender identity _id from List sender identities.
from.address
string
optional
From address. Default: the identity's default From.
from.name
string
optional
Display name. Default: the identity's display name.
replyTo
string
optional
Reply-to address. Default: the identity's reply-to.
toName
string
optional
Recipient display name (up to 200 characters).
clientRef
string
optional
Your own reference. Also makes retries safe, like the Idempotency-Key header.
templateId
string
one of
An approved email template. Send this, or subject with html / text.
locale
string
optional
Language version of the template, e.g. ar. Unknown versions fall back to the template's default.
variables
object
optional
Token values for the subject and body. Keys are letters, digits and _; values are text, numbers or true/false.
attachments
object[]
optional
Files to attach (up to 10).
attachments[].filename
string
required
File name with an allowed extension, e.g. INV-1001.pdf (longer than 150 characters is shortened).
Phone a contact from your own systems. On the answered call Relay can speak a message, play one of your recordings, run a call flow (a menu such as "press 1 to confirm"), or let a Voice AI agent hold the conversation.
- Calls are billed per minute in your plan's increments; unanswered calls are free. - Outgoing calls must be enabled for your account by Relay.
POST/api/v1/voice/callsMessaging hostAPI key
Place a voice call
Queues an outgoing call. On the answered call Relay speaks a message, plays one of your recordings, runs a call flow, or hands the call to a Voice AI agent — send exactly one of message, recordId / recording, flowId or agentId.
Send an Idempotency-Key header (or clientRef) so a retried request never places a second call.
Use Get call status with the returned callId to follow the call.
Message text is never stored after the call.
Request body
Field
Type
Required
Description
to
string
required
Number to call, in international format (+9665…).
message
object | string
one of
Text Relay speaks. A plain string is the same as { "text": "…" }.
message.text
string
conditional
What to say, up to 1000 characters. Required with message. Add a pause with <break time='3s'/> (up to 30 seconds).
message.language
string
optional
Language of the text, e.g. en-US, ar-SA.
message.voice
string
optional
Voice to speak with: Kore, Puck, Charon, Aoede, Fenrir, Leda, Orus or Zephyr. Any other name uses the default voice.
message.repeat
integer
optional
Say it 1–3 times (default 1).
message.pressToRepeat
boolean
optional
Offer "press 1 to hear it again" after the last repeat.
recordId
string
one of
One of your recordings (from Upload a recording or Voice → Recordings), played once.
recording
object
one of
A recording with options — use instead of recordId.
recording.recordId
string
conditional
The recording to play. Required with recording.
recording.repeat
integer
optional
Play it 1–3 times (default 1).
recording.pressToRepeat
boolean
optional
Offer "press 1 to hear it again" afterwards.
recording.language
string
optional
Language of the "press 1" prompt, e.g. ar-SA.
flowId
string
one of
A published call flow with *Outbound calls* turned on.
agentId
string
one of
An active Voice AI agent.
from
string
optional
One of your numbers that can place calls. Default: the flow's or agent's number; for a message or a recording, your first calling number.
variables
object
optional
Flat key/value pairs. Spoken in flow prompts as {name}, or given to the agent as context.
transactional
boolean
optional
true for calls the person asked for, such as a verification code: placed outside quiet hours and not blocked by the marketing opt-out list.
clientRef
string
optional
Your own reference (up to 100 characters); also makes retries safe, like Idempotency-Key.
ringTimeoutSec
integer
optional
How long the phone rings before the call counts as unanswered: 10–60 seconds (default 30).
statusCallbackUrl
string
optional
An https address that receives the call's final status once, as a GET.
Parameters: callid, status (COMPLETED, NO_ANSWER, BUSY, REJECTED or FAILED), status_timestamp, call_initiated_at, call_ringing_at, call_answered_at, call_finished_at (ISO 8601, UTC).
Times the call never reached are left out.
Retried within minutes if your server does not answer 2xx.
statusCallbackEndpoint is accepted as the same field.
dtmfCallbackUrl
string
optional
With message or a recording: listen for a key press while it plays, e.g. "press 1 to confirm".
The first key is sent to this https address as a GET with callid and dtmf (the key) added to it.
Then the call ends: a message speaks the rest of its text first, a recording stops.
A message listens through each <break>, or for 5 seconds at the end.
A recording listens while it plays and for 5 seconds after.
{
"error": "Provide exactly one of `message`, `recordId`, `flowId` or `agentId`",
"code": "invalid_request"
}
404
The recordId is not one of your recordings
{
"error": "Recording not found — upload it first (POST /api/v1/voice/file) and use the recordId it returns",
"code": "recording_not_found"
}
401
Missing or invalid API key
{
"error": "Missing API key"
}
403
Voice is not enabled on your account
{
"error": "Voice is not enabled on your account. Contact your account manager to enable it.",
"code": "channel_disabled"
}
402
Balance too low for a call
{
"error": "Your balance does not cover a call — top up your wallet",
"code": "insufficient_funds"
}
403
Outgoing calls not enabled, destination not allowed, or from not yours
{
"error": "Outbound calling is not enabled for your account — contact support to enable it",
"code": "outbound_not_enabled"
}
409
Flow not published / not outbound, agent inactive, quiet hours, opted-out contact, or no calling number
{
"error": "This call flow is not enabled for outbound calls — turn on \"Outbound calls\" in the flow",
"code": "flow_not_outbound"
}
429
Too many calls per second, or the workspace's monthly call limit
{
"error": "Too many calls started in the last second — try again shortly",
"code": "rate_limited"
}
GET/api/v1/voice/calls/:idMessaging hostAPI key
Get call status
The state of a call you placed, with the end reason, talk time, billed seconds and charge.
Status moves queued → ringing → answered → completed, or ends as no_answer, busy, rejected or failed.
Agent calls include the transcript; call-flow calls include the menu choices.
ringingAt is when the call started ringing. A call placed with statusCallbackUrl includes statusCallback: state (pending, sent or failed), the HTTP status your address answered with, and sentAt.
A message or recording with dtmfCallbackUrl includes dtmf: the key pressed (digits), the HTTP status your address answered with (callbackStatus, 0 = no answer) and when (at).
Parameters
Name
In
Type
Description
id *
path
string
The callId returned by POST /api/v1/voice/calls 66f1c0ffee0000000000beef
For systems moving from the previous platform: send the same call body you sent there, unchanged. Only the address and the API key change. Relay places it as a spoken-message call, with the same checks and answer as Place a voice call.
from may be a sender name: the call shows your first calling number. A number of yours is used as the caller ID.
A key pressed while the text plays is sent to dtmfCallbackEndpoint as a GET with callid and dtmf added to the address.
<break time='6s'/> in sayText is a pause; the call listens for a key through it.
callerVoice is matched to the closest Relay voice. neuralLang is accepted and ignored.
Follow the call with Get call status.
Request body
Field
Type
Required
Description
to
string
required
Number to call, in international format (+9665…).
sayText
string
required
What to say, up to 1000 characters, with optional <break time='6s'/> pauses.
lang
string
optional
Language of the text, e.g. ar-AE.
callerVoice
string
optional
Voice name from the previous platform (e.g. Hala); matched to a Relay voice.
repeatition
integer
optional
Say it 1–3 times (default 1; higher values count as 3).
ringingDuration
integer
optional
Seconds the phone rings before the call counts as unanswered (10–60, default 30).
enabledtmf
boolean
optional
Listen for a key press. Requires dtmfCallbackEndpoint.
dtmfCallbackEndpoint
string
conditional
https address that receives the key pressed. Required when enabledtmf is true.
from
string
optional
Sender name or one of your calling numbers.
statusCallbackEndpoint
string
optional
https address that receives the call's final status once, as a GET — the same request as statusCallbackUrl on Place a voice call.
Place a call with an execution plan (previous platform format)
For systems moving from the previous platform's Advanced Call: send the same body and XML plan you sent there, unchanged. Only the address and the API key change. The same checks apply as Place a voice call.
Verbs:<say> (text to speech, with reps, voice, lang), <play recordId=…> (one of your recordings), <gather> (speaks its text and collects keys) and <close/>, run in order. Others (async-gather, record, dial, redirect, play soundurl) return 400.
Key presses: always on <gather>; on <say> / <play> with enableDTMF='true'. Waits waitduration s for the first key (default 4), innertimeout between keys (3), totaltimeout in all (180).
One key with exitOnFirstDTMF='true', else up to maxchar, ending on stopchar.
Repeat: on <gather> with enablerep='true', pressing repchar replays the prompt, up to repcount times.
dtmfCallbackURL (url on <gather>; may be empty): receives a GET with dtmf and callid when the verb stops listening. dtmf is empty when nothing was pressed.
Next plan: if your reply (within 15 s, up to 32 KB) is a plan, it replaces the rest of the call. Any other reply: the plan goes on.
recordId: a Relay recordId, or the alias you gave the recording when uploading it (use your previous file names as aliases).
Body keys are read in any case (To, ExecutionPlan). The answer is 200 { callId }. Follow the call with Get call status.
Request body
Field
Type
Required
Description
to
string
required
Number to call, in international format, with or without +.
executionPlan
string
required
The XML plan: <begin>…</begin> with the verbs above, up to 32 KB and 50 verbs.
statusCallbackEndpoint
string
optional
https address that receives the call's final status once, as a GET — the same request as statusCallbackUrl on Place a voice call.
ringingDuration
integer
optional
Seconds the phone rings before the call counts as unanswered (10–60, default 30).
callerVoice
string
optional
Default voice for <say>: a previous-platform name (e.g. Hala) is matched to a Relay voice.
isCampaign
boolean
optional
true for marketing calls: quiet hours and the opt-out list apply. Default: a transactional call.
from
string
optional
One of your calling numbers. A sender name is ignored and your first calling number is used.
{
"error": "invalid recordId in play verb",
"code": "invalid_request",
"message": "invalid recordId in play verb"
}
401
Missing or invalid API key
{
"error": "Missing API key",
"message": "Missing API key"
}
402
Balance too low for a call
{
"error": "Your balance does not cover a call — top up your wallet",
"code": "insufficient_funds",
"message": "Your balance does not cover a call — top up your wallet"
}
403
Outgoing calls not enabled, or destination not allowed
{
"error": "Outbound calling is not enabled for your account — contact support to enable it",
"code": "outbound_not_enabled",
"message": "Outbound calling is not enabled for your account — contact support to enable it"
}
404
A recordId in the plan is not one of your recordings
{
"error": "Recording \"IVR_Welcome_AR-1792410256556.wav\" not found — upload it first (POST /api/v1/voice/file?alias=<its name>)",
"code": "recording_not_found",
"message": "…"
}
429
Too many calls per second, or the workspace's monthly call limit
{
"error": "Too many calls started in the last second — try again shortly",
"code": "rate_limited",
"message": "Too many calls started in the last second — try again shortly"
}
POST/api/v1/voice/fileMessaging hostAPI key
Upload a recording
Adds an audio file to your recordings library and returns its recordId. Pass it as recordId to Place a voice call, or use it as a prompt in your call flows.
Size: up to 16,777,216 bytes (about 17 minutes); the upload must finish within 60 seconds.
Uploading the same audio again returns the same recordId with duplicate: true.
The recording also appears in the portal under Voice → Recordings (play, rename, delete).
Parameters
Name
In
Type
Description
name
query
string
Name shown in the portal (up to 80 characters). Default: the file name. Welcome message
alias
query
string
Your own ID for the recording, e.g. the file name your previous platform used. It then works wherever a recordId does, exactly as written (case matters).
- Up to 256 characters; no .., /, \ or control characters. - Unique in your account: an alias already on another recording returns 409 alias_taken. IVR_Welcome_AR-1792410256556.wav
{
"reqId": "…",
"error": "Invalid or inactive API key"
}
403
Voice is not enabled on your account, or the workspace is paused
{
"reqId": "…",
"error": "Voice is not enabled on your account. Contact your account manager to enable it.",
"code": "channel_disabled"
}
408
The upload took longer than 60 seconds
{
"reqId": "…",
"error": "The upload did not finish within 60 seconds",
"code": "upload_timeout"
}
409
Your recording library is full (1000 recordings), or alias already names another recording
{
"reqId": "…",
"error": "Your recording library is full (1000) — delete recordings you no longer use",
"code": "library_full"
}
413
File too large
{
"reqId": "…",
"error": "The file is too large: the limit is 16777216 bytes",
"code": "file_too_large"
}
415
Sent as JSON or a form instead of the file
{
"reqId": "…",
"error": "Send the WAV file as the request body (Content-Type: audio/wav) or as multipart/form-data",
"code": "unsupported_media_type"
}
502
The file could not be stored — safe to retry
{
"reqId": "…",
"error": "Failed to store the file — try again",
"code": "storage_failed"
}
One call with its full transcript, the tools the agent used, the end reason, the billed duration and charge, and the handover case id when the agent passed the caller to your team.
{
"_id": "66f1...",
"status": "completed",
"endReason": "agent_hangup",
"durationSec": 75,
"billableSec": 120,
"transcript": [
{
"role": "agent",
"text": "Hello Sara, this is Relay Clinic calling about your appointment."
},
{
"role": "caller",
"text": "Yes, go ahead."
}
],
"caseId": null
}
404
Not found
{
"error": "Call not found"
}
Automations
Start an automation from your own systems: one with the API trigger is started with an API key; one with the Inbound webhook trigger by a signed POST to its own URL.
- Both identify the person by phone number; a number not yet in your contacts is added. - The data you send becomes fields your steps use as {field} — in messages, If/else and Switch conditions. - In the builder, the trigger panel shows the ready-to-copy call and lets you list required fields: a call missing any of them is refused before anything is created.
POST/api/webhooks/inbound/:slugManagement host
Inbound webhook (signed)
The URL of an automation with the Inbound webhook trigger. Create the endpoint in the builder (trigger panel → New endpoint): you choose the slug and where the phone number sits in your JSON, and see the endpoint's secret once (rotate it there).
Signing (required): HMAC-SHA256 (or SHA-512, if set on the endpoint) of the exact raw body with the endpoint secret, hex-encoded, in X-Signature-256 (or the endpoint's header). A sha256= prefix is accepted.
Sign the bytes you send, not a re-serialised copy. Bash: printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$SECRET" | sed 's/^.*= //'. Node.js: crypto.createHmac('sha256', secret).update(body).digest('hex').
Who: the phone is read from the endpoint's contact path — $.phone by default; dotted paths and list positions such as $.customer.phone or $.items[0].mobile work. A new number is added to your contacts.
Your data: the whole body is available to steps — each top-level key as {key}, a nested value as {parent_child} (up to three levels), a list as {key_count}. A body key never replaces a contact field.
Required fields: a body where one is missing, null or blank (a.b for nested keys) gets 400 missing_fields after the signature check, before any contact is created.
Waiting runs: if the person has a run of this automation paused on *Wait for event → webhook callback*, the call resumes it (the body is saved on the run) instead of starting a new one. Required fields are not checked then.
No idempotency key: each accepted call starts a new run.
Parameters
Name
In
Type
Description
slug *
path
string
The endpoint slug chosen in the builder shop-order-paid
Request body
Field
Type
Required
Description
phone
string
conditional
The person's phone number, at the endpoint's contact path ($.phone by default — it may sit elsewhere, e.g. customer.phone).
order_id
any
optional
An example of your own data: any other key is available to steps as {order_id}.
amount
any
optional
Another example key: {amount}.
customer
object
optional
A nested object: its fields become {customer_tier} and so on.
Any JSON object up to 1 MB, sent with Content-Type: application/json and the signature header — the cURL sample below leaves the signature out.
Body is not JSON, no phone at the contact path, or an invalid phone number
{
"error": "Could not resolve contact identifier from path \"$.phone\""
}
401
Signature header missing, or the signature does not match
{
"error": "Invalid signature"
}
403
Contact limit of your plan reached (new phone), or the workspace is read-only
{
"error": "Workspace is read-only (subscription past due) — automations are paused"
}
404
Unknown slug, or the endpoint is disabled
{
"error": "Webhook endpoint not found"
}
409
Automation not active, emergency stop engaged, or a waiting run could not be resumed
{
"error": "Automation is paused — cannot enroll"
}
429
Concurrent-run limit or per-contact frequency cap reached
{
"error": "Frequency cap exceeded for this contact"
}
Workspaces
Workspaces split your account's sending. Each has its own monthly limit per channel, an optional spend budget, its members, the assets (senders, numbers, stores) it may use, and the credentials assigned to it.
- Paths keep the original /apps spelling so existing integrations keep working. - Limit units: SMS in message parts, WhatsApp and email in outbound messages, voice in outgoing calls placed through the voice API. - The Main Workspace is always uncapped and uses every account asset.
GET/api/mgmt/v1/appsManagement hostAPI key
List workspaces
Returns the organisation's workspaces, Main Workspace first.
Account admins see every workspace; other users see only the workspaces they belong to.
An API key assigned to a workspace sees only that workspace.