Guides
Tokens and authentication
Every request except the health check carries a token. A token belongs to one integration, carries its own permissions and limits, and can be stopped by the hotel at any moment.
What a token is#
The hotel issues tokens from its admin dashboard, one per application or environment. When a token is created you see the whole token once; after that the hotel can only see its name and its last four characters.
ems_k2q7mbx4ra3d_h4c5s3oe2n6wx7fm2yqjl4dkvt3pgw5za6cr2xb4| Part | Meaning |
|---|---|
ems_ | Marks it as a key for this API, so secret scanners and people can recognise it. A test token starts ems_test_. |
| 12 characters | The token's public id. It appears in the hotel's dashboard and logs; you can quote it when asking for help. |
| 40 characters | The secret: 200 random bits. Only a SHA-256 hash of it is stored, so nobody can read it back, including the hotel. |
The characters are lowercase a to z and 2 to 7, so a token never needs quoting or escaping.
Each token carries:
- permissions:
send,read, or both; - sender addresses it may use as
from, chosen from the addresses the hotel has approved for the API; - limits: messages per minute and messages per day, and optionally per month;
- an optional expiry time.
The hotel may also attach it to a client (your app, which the hotel can pause as a whole, and which may be limited to some recipient domains), limit it to some templates or to templates only, and limit the addresses it may be used from.
Test tokens (ems_test_...) go through every check a live token does and their messages are recorded, but nothing is ever sent: the answer and the message say "status": "sent", "test": true. Use one while you build your integration.
Sending the token#
Put it in the Authorization header with the Bearer scheme, on every request, over HTTPS:
GET /v1/me HTTP/1.1
Host: email.madagascarhotelags.com
Authorization: Bearer ems_k2q7mbx4ra3d_h4c5s3oe2n6wx7fm2yqjl4dkvt3pgw5za6cr2xb4Never put a token in a URL, a query string, a cookie or a request body: those end up in browser history, proxy logs and analytics tools.
What each permission allows#
| Request | Needs |
|---|---|
GET /v1/health | nothing (no token) |
GET /v1/me | any valid token |
POST /v1/messages | send |
GET /v1/messages/{id} | read, and only for messages sent with the same token |
Ask for only what your integration uses. A service that only sends needs send; a dashboard that only shows status needs read.
Check a token#
curl -sS https://email.madagascarhotelags.com/v1/me \
-H "Authorization: Bearer $EMAIL_API_TOKEN"$headers = @{ Authorization = "Bearer $env:EMAIL_API_TOKEN" }
Invoke-RestMethod -Uri https://email.madagascarhotelags.com/v1/me -Headers $headersconst res = await fetch('https://email.madagascarhotelags.com/v1/me', {
headers: { Authorization: `Bearer ${process.env.EMAIL_API_TOKEN}` },
});
console.log(res.status, await res.json());import os, requests
res = requests.get(
"https://email.madagascarhotelags.com/v1/me",
headers={"Authorization": f"Bearer {os.environ['EMAIL_API_TOKEN']}"},
timeout=10,
)
print(res.status_code, res.json())<?php
$ch = curl_init('https://email.madagascarhotelags.com/v1/me');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('EMAIL_API_TOKEN')],
]);
var_dump(json_decode(curl_exec($ch), true));{
"token": {
"id": "k2q7mbx4ra3d",
"name": "Booking site",
"mode": "live",
"client": "Booking site",
"scopes": ["send", "read"],
"senders": ["booking@madagascarhotelags.com"],
"templates": null,
"templates_only": false,
"rate_per_min": 10,
"daily_cap": 50,
"monthly_cap": null,
"expires_at": null
},
"usage": { "sent_today": 12, "remaining_today": 38, "sent_this_month": 140, "remaining_this_month": null },
"api": { "enabled": true }
}senders lists the addresses this token can use right now: the hotel can withdraw an address at any time. sent_today and remaining_today count messages in the current UTC day, and the _this_month pair in the current UTC month (null when there is no monthly limit).
When a token is refused#
| Status | code | What it means |
|---|---|---|
| 401 | invalid_token | Missing, malformed, unknown, wrong or deleted. These all look the same on purpose, so nobody can probe which tokens exist. |
| 401 | token_expired | The token's expiry time has passed. |
| 403 | token_blocked | The hotel blocked the token. Do not retry; contact the hotel. |
| 403 | insufficient_scope | The token lacks the permission the endpoint needs. |
| 403 | client_paused | The hotel paused your app's client, which stops all its tokens. Contact the hotel. |
| 403 | ip_not_allowed | The token may be used only from some addresses, and this request came from another. |
| 503 | api_disabled | The hotel has switched the API off for everyone. Retry later. |
A block, an expiry, a rotation or a deletion takes effect on the very next request: the API reads the token's record on every call and keeps no copy.
Keeping it safe#
- Store it as a server-side secret: your platform's secret store or an environment variable that is not committed. On Cloudflare Workers,
npx wrangler secret put EMAIL_API_TOKEN. - Never ship it in browser JavaScript, a mobile app or a desktop app. Anyone with the app can read it. The API sends no CORS headers, so browsers cannot call it from other sites anyway.
- Use one token per application and per environment (production, staging), so one can be replaced without touching the others.
- Do not log it. Log the message id and the token's public id instead.
- If a token may have leaked (pushed to a repository, pasted in a chat, sent by email), tell the hotel at once at team@madagascarhotelags.com. The hotel can rotate it (new secret, same settings) or block it within seconds.
Last reviewed 2026-10-01.