1. Create a client session
The same external client ID returns the existing session, so repeated setup does not create duplicates.
ENTERPRISE INTEGRATION
Use your enterprise API key on your backend. Map each client to a stable externalClientId, create their session, and return a short-lived pairing URL to your frontend. All sessions belong to your enterprise account.
The same external client ID returns the existing session, so repeated setup does not create duplicates.
Choose an exact approved website origin. The pairing URL lasts 10 minutes and can read/connect only this session.
Your client scans the QR without leaving your website. Receive connection status from the embed.
Your own backend must authenticate the client before calling this function. Derive the client ID from that authenticated record; never accept another client’s ID or a website origin directly from an untrusted request.
const BASE = 'https://api.relaywa.com/api/v1/b2b';
const KEY = process.env.RELAYWA_ENTERPRISE_KEY;
async function relaywa(path, body) {
const res = await fetch(BASE + path, {
method: 'POST',
headers: {
Authorization: 'Bearer ' + KEY,
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
});
if (!res.ok) throw new Error(await res.text());
return res.json();
}
// authorizedClient is loaded after YOUR app verifies client access.
async function pairingFor(authorizedClient) {
const session = await relaywa('/sessions', {
externalClientId: String(authorizedClient.id),
name: authorizedClient.companyName
});
await relaywa('/sessions/' + session.id + '/connect', {});
return relaywa('/sessions/' + session.id + '/embed', {
origin: authorizedClient.approvedWebsiteOrigin
});
}
// Return { embedUrl, expiresInSeconds, sessionId } to your frontend.
// Keep KEY on your backend. Never include it in HTML or browser JavaScript.Create the iframe using the embedUrl returned by your backend. Add your own site and client sites in the partner portal or through PATCH /domains first. The iframe is restricted to the chosen origin.
const pairing = await fetch('/your-api/whatsapp/pairing').then(r => r.json());
const frame = document.createElement('iframe');
frame.src = pairing.embedUrl;
frame.title = 'Connect your WhatsApp number';
frame.width = '100%';
frame.height = '560';
frame.style.border = '0';
document.getElementById('whatsapp-pairing').replaceChildren(frame);
window.addEventListener('message', event => {
if (event.origin !== 'https://relaywa.com') return;
if (event.source !== frame.contentWindow) return;
if (event.data?.type === 'relaywa.session.status') {
console.log(event.data.sessionId, event.data.status);
}
});The embed posts status updates only to its approved parent origin. It automatically refreshes the QR while the link is valid. Request a new pairing URL from your backend after expiry. Customize iframe width/height to fit your page.
Base URL: https://api.relaywa.com/api/v1/b2b. Every endpoint below requires Authorization: Bearer YOUR_ENTERPRISE_KEY. API keys are scoped to one enterprise organization.
| Method | Endpoint | Purpose |
|---|---|---|
| GET | /account | Domain, approved origins, billing period and unlimited-session entitlement |
| GET / PATCH | /domains | Read/update approved client origins: { allowedOrigins: ["https://client.example"] } |
| GET | /sessions | List your company’s sessions and external client IDs |
| POST | /sessions | Create or reuse: { externalClientId, name, phoneHint? } |
| GET | /sessions/:id | Session state and connection information |
| GET | /sessions/:id/qr | QR dataUrl and expiresAt; available=false while waiting |
| POST | /sessions/:id/connect | Queue connection or pairing |
| POST | /sessions/:id/restart | Request reconnect |
| POST | /sessions/:id/disconnect | Log out the linked WhatsApp account |
| POST | /sessions/:id/embed | Create a 10-minute URL: { origin: "https://client.example" } |
| POST | /sessions/:id/messages | Send text: { to, text, clientMessageId } |
| GET | /sessions/:id/credentials | Get the linked session’s messaging API key after connection |
| PATCH | /sessions/:id | Update name or phoneHint |
| DELETE | /sessions/:id | Remove a pending/logged-out session with no operation in progress |
| GET | /sessions/:id/logs | Recent connection events |
| GET / POST | /webhooks | List/create signed webhook endpoints; { name, url, eventTypes } |
401: missing, revoked or expired credentials. 403: inactive enterprise subscription or unapproved embed origin. 404: session unavailable to this account. 409: conflicting name or operation. Connection commands run asynchronously; poll the session status or use signed webhooks.
$100 monthly or $1,000 annually for unlimited sessions. Contact support@relaywa.com to onboard, renew, or change the company domain. Manage approved client website origins yourself through the portal or API. You can create and revoke server keys in the partner portal. RelayWA administrators manage activation after confirmed payment.
Session limits are unlimited. WhatsApp account conditions, message pacing, and the existing messaging safety controls still apply.