Authentication and scopes
Create API keys, send them with each request, and give each key only the scopes it needs.
Every request needs an API key in the Authorization header:
GET /v1/conversations HTTP/1.1
Host: api.chatwise.so
Authorization: Bearer <your API key>A key belongs to one workspace, so no request names a workspace.
Create a key
Workspace admins create keys in the dashboard, under Settings → Developer → API Keys (open it). Choose a name, the permissions and when it expires: in at most 365 days, or never.
The key is shown once. Chatwise stores only a hash of it and can't show it again.
Keep keys on your server. Don't put one in a web page, a mobile app or a repository: anyone who has it can use it.
Scopes
A key can do only what its scopes allow.
| Scope | In the dashboard | What it allows |
|---|---|---|
conversations:read | Read conversations | List, find and read conversations. |
messages:read | Read messages | List, search and read messages. Also needed for anything that would give the key a message by webhook, see below. |
messages:send | Send messages | Send approved WhatsApp templates. |
templates:read | Read templates | List and read WhatsApp templates. |
templates:write | Create templates | Create WhatsApp templates and submit them to Meta. |
webhooks:read | Read webhook endpoints | List webhook endpoints, their deliveries and the event types. |
webhooks:write | Manage webhook endpoints | Create, change, test and delete webhook endpoints, rotate their secrets and redeliver. |
One scope doesn't include another: webhooks:write alone can't list endpoints. Each page of the API reference names the scope its route needs.
You can't change a key's scopes. Create another key and revoke the old one.
When messages:read is needed too
Webhooks carry messages, so a key must not get a message by webhook that it couldn't read through the API. With message.* events, these need messages:read as well:
| What you do | Scope | Also |
|---|---|---|
Create an endpoint with message.* events | webhooks:write | messages:read |
| Change an endpoint that has them, or add them | webhooks:write | messages:read |
| Rotate the secret of an endpoint that has them | webhooks:write | messages:read |
Read a delivery of a message.* event | webhooks:read | messages:read |
Redeliver a message.* event | webhooks:write | messages:read |
Testing and deleting an endpoint, and listing its deliveries, don't need it: they return no messages.
Rotate a key
- Create a key with the same scopes.
- Deploy it.
- Make a request with it.
- Revoke the old key in the dashboard.
A revoked or expired key stops working right away: it answers 401.
When a key is refused
| Status | Message | What to do |
|---|---|---|
| 401 | A valid Bearer API key is required | Send Authorization: Bearer and the key. |
| 401 | Invalid or revoked API key | Check the key. It may have been revoked, or have expired. |
| 401 | Invalid API key | Chatwise couldn't check the key. Try again. |
| 403 | API key does not have the required scope: … | Use a key with the scope the message names. |
| 400 | Message events need an API key with the messages:read scope too. | Subscribe with a key that also has messages:read. |
| 403 | Changing an endpoint that receives message events needs an API key with the messages:read scope too. | The same, for changing an endpoint or rotating its secret. |
| 403 | Reading a message event's delivery needs an API key with the messages:read scope too. | The same, for reading or redelivering a delivery. |
| 429 | API key rate limit exceeded | Wait, then go on. |