Docs API
Authentication
Make an API token in the dashboard and send it in the Authorization header of each request.
The API uses personal API tokens from Laravel Sanctum. Each token belongs to one user. A request with the token acts for that user and sees the data of the account of that user.
Make an API token
- Log in to the dashboard.
- Open Settings, then API Tokens (
/settings/api-tokens). - In Token name, type a name for the token. The name is text of 255 characters or fewer.
- In Access, select Read only or Read and write.
- In Expiration, select Never, or a number of days: 30, 90 or 365.
- Click Create Token.
- Copy the token from the Token created successfully box.
- Keep the token in a secret store.
Warning: Copy the token before you leave the page. BYOMailer shows the full token only one time.
The Existing Tokens list shows the name, the access and the expiration date of each token, when you made it, and when it was last used.
A team member with the Viewer role cannot make API tokens.
Warning: Never put an API token in browser code or in a public repository. The token gives full access to the data of your account.
Send the token
Send the token in the Authorization header of each request:
Authorization: Bearer <your-token>
Example:
curl https://byomailer.example/api/v1/contacts \
-H "Authorization: Bearer <your-token>" \
-H "Accept: application/json"
The same token also works for the MCP server. See Connect clients.
Token abilities and expiry
Each token has Sanctum abilities. The Access choice sets them:
| Access | Abilities | What the token can do |
|---|---|---|
| Read only | read |
Read data. Each request that changes data or sends mail gets 403. |
| Read and write | read, write |
Read and change data, and send mail. |
A token that BYOMailer made before access levels existed has all abilities (*). It has read and write access.
The EnforceAccessLevel middleware checks each API request:
- A request with a token that has no
readability gets403with the messageThis API token has no read access. - A
POST,PUT,PATCHorDELETErequest with nowriteability gets403with the messageYou have read-only access. POST /api/v1/newsletters/contacts/previewonly reads data, so a read-only token can use it.
A token with an expiration date stops working after that date. The next request gets 401. A token with Never does not expire, because expiration in config/sanctum.php is null.
If you set the SANCTUM_TOKEN_PREFIX environment variable, Sanctum adds that prefix to new tokens. Secret scanners can then find a leaked token.
Roles
The role of the token user also limits the API:
- A user with the Viewer role has read-only access. Each request of a Viewer that changes data gets
403, also with a read and write token. - Only a user with the
adminrole can use the webhook endpoints. A token of another user gets403on those endpoints, with the messageOnly an admin of the account can manage webhook endpoints.
Revoke a token
- Open Settings, then API Tokens.
- In Existing Tokens, find the token.
- Click Delete on the row of the token.
BYOMailer deletes the token. The next request with that token gets 401.
Tokens that BYOMailer refuses
BYOMailer checks the user of the token on each request. It refuses the token, with 401, in these conditions:
| Condition of the user | How it happens | What happens to the tokens |
|---|---|---|
| Deactivated | The owner deactivates the user in Admin, Users. | BYOMailer keeps the tokens. If the owner reactivates the user, the tokens work again. |
| Archived | An admin archives the team member in Settings, Team. | BYOMailer deletes all the tokens of the member. |
| Invited | The member has an open invitation (invite_expires_at is set). |
The member cannot use a token before the member accepts the invitation. |
The same rule applies to the MCP server, because it also uses Sanctum tokens. See Teams and Accounts and registration.
The 401 response
A request with no token, a wrong token, a revoked token or a refused token gets this response:
{
"message": "Unauthenticated."
}
The response is 401 with JSON, also when the request has no Accept: application/json header.