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.

Token shape
ems_k2q7mbx4ra3d_h4c5s3oe2n6wx7fm2yqjl4dkvt3pgw5za6cr2xb4
PartMeaning
ems_Marks it as a key for this API, so secret scanners and people can recognise it. A test token starts ems_test_.
12 charactersThe token's public id. It appears in the hotel's dashboard and logs; you can quote it when asking for help.
40 charactersThe 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:

HTTP
GET /v1/me HTTP/1.1
Host: email.madagascarhotelags.com
Authorization: Bearer ems_k2q7mbx4ra3d_h4c5s3oe2n6wx7fm2yqjl4dkvt3pgw5za6cr2xb4

Never 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#

RequestNeeds
GET /v1/healthnothing (no token)
GET /v1/meany valid token
POST /v1/messagessend
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#

Shell
curl -sS https://email.madagascarhotelags.com/v1/me \
  -H "Authorization: Bearer $EMAIL_API_TOKEN"
Response 200
{
  "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#

StatuscodeWhat it means
401invalid_tokenMissing, malformed, unknown, wrong or deleted. These all look the same on purpose, so nobody can probe which tokens exist.
401token_expiredThe token's expiry time has passed.
403token_blockedThe hotel blocked the token. Do not retry; contact the hotel.
403insufficient_scopeThe token lacks the permission the endpoint needs.
403client_pausedThe hotel paused your app's client, which stops all its tokens. Contact the hotel.
403ip_not_allowedThe token may be used only from some addresses, and this request came from another.
503api_disabledThe 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.