Authentication
Which key to use, and what each request looks like with it.
You have two kinds of key. Pick by how many WhatsApp numbers the code talks to.
| Session token | Account key | |
|---|---|---|
| Looks like | ch_live_... | ak_live_... |
| Works on | One WhatsApp number | Every number on your account |
| Use it for | Sending and receiving on that number | Creating sessions, and services that run several numbers |
| Session name in requests | Not needed | Required on every session request |
| Where to get it | Console, shown on each session | Console → Account API Keys |
| If it leaks | One number is exposed | Every number is exposed |
Send either key in one of these headers. Both work on every endpoint:
Authorization: Bearer YOUR_KEY
x-api-key: YOUR_KEYThe same request with each key
The only difference is the session name. A session token already knows its session. An account key does not, so you name it.
Send a message
With a session token, leave session out:
curl -X POST https://wp-rapidapi.retentionstack.agency/v1/sendText \
-H "Authorization: Bearer ch_live_YOUR_SESSION_TOKEN" \
-H "Content-Type: application/json" \
-d '{"chatId": "15551234567", "text": "Your order is ready."}'With an account key, add session:
curl -X POST https://wp-rapidapi.retentionstack.agency/v1/sendText \
-H "Authorization: Bearer ak_live_YOUR_ACCOUNT_KEY" \
-H "Content-Type: application/json" \
-d '{"session": "SESSION_NAME", "chatId": "15551234567", "text": "Your order is ready."}'Endpoints with the session in the path
With a session token, put me where the session name goes. With an account key, put the name:
# session token
curl https://wp-rapidapi.retentionstack.agency/v1/me/auth/qr \
-H "Authorization: Bearer ch_live_YOUR_SESSION_TOKEN"
# account key
curl https://wp-rapidapi.retentionstack.agency/v1/SESSION_NAME/auth/qr \
-H "Authorization: Bearer ak_live_YOUR_ACCOUNT_KEY"Endpoints with the session in the query
Same rule: leave session out with a session token, add ?session=SESSION_NAME with an account key.
Which key each kind of request accepts
| Request | Session token | Account key |
|---|---|---|
| Messages, contacts, groups, presence | Its own session | Any of your sessions |
| QR code, pairing code, passkey | Its own session | Any of your sessions |
GET /v1/sessions (list) | Returns only its own session | Returns all your sessions |
POST /v1/sessions (create) | Not allowed (403) | Yes |
| Billing, account keys, rotating tokens | Console only | Console only |
A session token sent with another session's name returns 403. It never acts on a session other than its own.
Running several numbers
Create each session with your account key. The response includes the new session's channel_token. Store one token per number, and send each number's messages with its own token. That way your sending code never needs the account key or a session name. See Create a session from code.
Rotating a session token
Rotate a session token from the console. The old token stops working immediately, so deploy the new one first or expect a short outage.
Errors
| HTTP | Cause |
|---|---|
401 | No key, or the key is unknown or revoked |
403 | The session belongs to someone else, a session token named another session, or a session token tried to create a session |
Both use the standard error envelope.