Reference
API reference
The complete contract of version 1. The same information is available as an OpenAPI 3.1 document for code generators and API tools.
Basics#
| Base URL | https://email.madagascarhotelags.com |
| Version | v1, in the path |
| Authentication | Authorization: Bearer <token> (all endpoints except /v1/health) |
| Request body | application/json, UTF-8, at most 256 KiB |
| Responses | application/json; errors application/problem+json |
| Times | ISO 8601 in UTC, millisecond precision |
| Caching | every response is Cache-Control: no-store |
| Machine-readable | /openapi.json (OpenAPI 3.1) |
Headers#
| Header | Direction | Meaning |
|---|---|---|
Authorization | request | Bearer and your token. |
Content-Type | request | application/json on POST. Anything else is 415. |
Idempotency-Key | request | Optional on POST /v1/messages; 1 to 128 of A-Z a-z 0-9 . _ : - (at most 124 on POST /v1/messages/batch). |
Location | response | On 202: the path of the new message. |
Idempotent-Replayed | response | true when a 202 repeats an earlier answer for the same key. |
Retry-After | response | Seconds to wait, on 429 and 503. |
WWW-Authenticate | response | Bearer, on 401 invalid_token. |
Allow | response | The accepted methods, on 405. |
GET /v1/health#
/v1/healthno tokenAnswers whether the API is up. Use it for uptime monitors; it does not touch the database.
{ "ok": true, "service": "cf-email-api", "time": "2026-10-01T15:04:05.000Z" }GET /v1/me#
/v1/meany valid tokenThe token's identity, mode, client, permissions, current senders, templates, limits and its usage today and this month.
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));| Field | Type | Meaning |
|---|---|---|
token.id | string | The public id (12 characters). |
token.name | string | The name the hotel gave the token. |
token.mode | string | live, or test: checked and recorded, never sent. |
token.client | string or null | The app or service the token belongs to. |
token.scopes | string[] | send and/or read. |
token.senders | string[] | Addresses usable as from right now. |
token.templates | string[] or null | The templates it may send; null for any published one. |
token.templates_only | boolean | true when it may send templates only. |
token.rate_per_min | integer | Messages per minute. |
token.daily_cap | integer | Messages per UTC day. |
token.monthly_cap | integer or null | Messages per UTC month; null for no limit. |
token.expires_at | string or null | When the token stops working. |
usage.sent_today | integer | Messages accepted today (UTC). |
usage.remaining_today | integer | daily_cap minus sent_today. The shared allowance may run out sooner. |
usage.sent_this_month | integer | Messages accepted this month (UTC). |
usage.remaining_this_month | integer or null | monthly_cap minus sent_this_month; null for no limit. |
api.enabled | boolean | Always true in a successful answer. |
POST /v1/messages#
/v1/messagessend permissionAccepts a message for delivery.
curl -sS https://email.madagascarhotelags.com/v1/messages \
-H "Authorization: Bearer $EMAIL_API_TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: booking-4821-confirmation" \
-d '{
"to": ["guest@example.com"],
"subject": "Your stay is confirmed",
"text": "Luna checks in on Friday at 10:00. Reply to this email if anything changes.",
"html": "<p>Luna checks in on <strong>Friday at 10:00</strong>.</p><p>Reply to this email if anything changes.</p>"
}'$headers = @{
Authorization = "Bearer $env:EMAIL_API_TOKEN"
"Idempotency-Key" = "booking-4821-confirmation"
}
$body = @{
to = @("guest@example.com")
subject = "Your stay is confirmed"
text = "Luna checks in on Friday at 10:00."
} | ConvertTo-Json
Invoke-RestMethod -Method Post -Uri https://email.madagascarhotelags.com/v1/messages `
-Headers $headers -ContentType "application/json" -Body $bodyconst res = await fetch('https://email.madagascarhotelags.com/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.EMAIL_API_TOKEN}`,
'Content-Type': 'application/json',
'Idempotency-Key': 'booking-4821-confirmation',
},
body: JSON.stringify({
to: ['guest@example.com'],
subject: 'Your stay is confirmed',
text: 'Luna checks in on Friday at 10:00.',
}),
});
const result = await res.json();
if (!res.ok) throw new Error(`${result.code}: ${result.detail}`);
console.log(result.id); // msg_...import os, requests
res = requests.post(
"https://email.madagascarhotelags.com/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['EMAIL_API_TOKEN']}",
"Idempotency-Key": "booking-4821-confirmation",
},
json={
"to": ["guest@example.com"],
"subject": "Your stay is confirmed",
"text": "Luna checks in on Friday at 10:00.",
},
timeout=10,
)
result = res.json()
if not res.ok:
raise RuntimeError(f"{result['code']}: {result['detail']}")
print(result["id"]) # msg_...<?php
$ch = curl_init('https://email.madagascarhotelags.com/v1/messages');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . getenv('EMAIL_API_TOKEN'),
'Content-Type: application/json',
'Idempotency-Key: booking-4821-confirmation',
],
CURLOPT_POSTFIELDS => json_encode([
'to' => ['guest@example.com'],
'subject' => 'Your stay is confirmed',
'text' => 'Luna checks in on Friday at 10:00.',
]),
]);
$result = json_decode(curl_exec($ch), true);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 202) {
throw new RuntimeException($result['code'] . ': ' . $result['detail']);
}
echo $result['id']; // msg_...Body#
| Field | Type | Required | Rules |
|---|---|---|---|
to | address[] | yes | 1 or more |
cc | address[] | no | |
bcc | address[] | no | to + cc + bcc at most 10 unless the hotel set otherwise (1 to 50) |
from | address or { email, name? } | no | one of token.senders; default: the first |
reply_to | address | no | |
subject | string | yes, without a template | 1 to 998 characters after control characters become spaces |
html | string | html or text | 1 to 200,000 characters |
text | string | html or text | 1 to 100,000 characters |
tags | string[] | no | at most 5, each [A-Za-z0-9_-]{1,32} |
scheduled_at | string | no | ISO 8601, 1 minute to 72 hours ahead |
template_id | string | instead of subject, html, text | a published template, tpl_ then 2 to 60 of a-z, 0-9, _ (Templates) |
variables | object | with a template | the template's variables by name, each checked against its type |
locale | string | no | es or en; default Spanish, else the language the template has |
An address is "user@example.com" or "Name <user@example.com>" (at most 254 characters for the address part). Unknown fields are refused.
Responses#
| Status | When |
|---|---|
| 202 | Accepted: { id, status: "queued", created_at } and Location. Also a replay of a known Idempotency-Key (with Idempotent-Replayed: true and the message's current status). |
| 400 | invalid_json, invalid_request, unknown_field, invalid_address, too_many_recipients, invalid_schedule, invalid_idempotency_key |
| 401 | invalid_token, token_expired |
| 403 | token_blocked, insufficient_scope, sender_not_allowed |
| 405 | method_not_allowed |
| 413 | payload_too_large |
| 415 | unsupported_media_type |
| 422 | idempotency_key_reuse, unknown_template, invalid_variables, content_blocked |
| 429 | rate_limited, daily_cap_reached, api_budget_reached |
| 500 | internal |
| 503 | api_disabled, unavailable |
GET /v1/templates#
/v1/templatessend permissionThe templates the hotel has published, with what each one needs. Only published, active templates are listed; a send always uses the version published at that moment.
{ "templates": [ { "id": "tpl_booking_confirmed", "name": "Booking confirmed", "description": "", "version": 3, "locales": ["es", "en"], "variables": [ { "name": "guest_name", "type": "string", "required": true }, { "name": "check_in", "type": "date", "required": true } ] } ] }| Status | When |
|---|---|
| 200 | The templates. |
| 401 | invalid_token, token_expired |
| 403 | token_blocked, insufficient_scope |
GET /v1/messages/{id}#
/v1/messages/{id}read permissionOne message sent with the same token. id is msg_ followed by 26 lowercase letters and digits.
curl -sS https://email.madagascarhotelags.com/v1/messages/msg_01k6qzexample0000000000000 \
-H "Authorization: Bearer $EMAIL_API_TOKEN"$headers = @{ Authorization = "Bearer $env:EMAIL_API_TOKEN" }
Invoke-RestMethod -Uri https://email.madagascarhotelags.com/v1/messages/msg_01k6qzexample0000000000000 -Headers $headersconst res = await fetch(`https://email.madagascarhotelags.com/v1/messages/${id}`, {
headers: { Authorization: `Bearer ${process.env.EMAIL_API_TOKEN}` },
});
const message = await res.json();
console.log(message.status, message.error);res = requests.get(
f"https://email.madagascarhotelags.com/v1/messages/{message_id}",
headers={"Authorization": f"Bearer {os.environ['EMAIL_API_TOKEN']}"},
timeout=10,
)
message = res.json()
print(message["status"], message["error"])<?php
$ch = curl_init('https://email.madagascarhotelags.com/v1/messages/' . $messageId);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('EMAIL_API_TOKEN')],
]);
$message = json_decode(curl_exec($ch), true);
echo $message['status'];| Field | Type | Meaning |
|---|---|---|
id | string | The message id. |
status | string | queued, , sent, failed or dead |
from | string | The sender address used. |
to | string[] | The To addresses. |
cc_count, bcc_count | integer | How many Cc and Bcc addresses. |
subject | string | |
scheduled_at | string or null | The requested send time. |
created_at | string | When it was accepted. |
sent_at | string or null | When the mail system accepted it. |
attempt | integer | Hand-off attempts so far. |
error | string or null | Why, for failed and dead. Text for people, not a code. |
delivery | string or null | The latest verdict after sending: delivered, deferred, bounced, blocked, complained or unsubscribed. null means not known yet, not failed. A deferral never replaces a final verdict. |
delivery_at | string or null | When delivery was last set. |
suppressed | integer | Recipients removed by the suppression list. |
test | boolean | true for a message a test token sent: recorded, never sent. |
canceled_at | string or null | When it was cancelled. |
| Status | When |
|---|---|
| 200 | The message. |
| 401 | invalid_token, token_expired |
| 403 | token_blocked, insufficient_scope |
| 404 | not_found: no such message for this token, or a malformed id. |
POST /v1/messages/batch#
/v1/messages/batchsend permissionAccepts up to 50 messages in one request: { "messages": [ ... ] }, each exactly the body of POST /v1/messages. Each message is checked and counted against every limit as if it were sent alone, and is accepted or refused on its own: one bad message does not stop the others.
{ "accepted": 2, "refused": 1, "results": [
{ "index": 0, "id": "msg_01j9z8x7w6v5t4s3r2q1p0n9m8", "status": "queued", "created_at": "2026-10-10T14:00:00.000Z" },
{ "index": 1, "error": { "code": "invalid_address", "detail": "to[0] is not a valid address." } },
{ "index": 2, "id": "msg_01j9z8x7w6v5t4s3r2q1p0n9m9", "status": "queued", "created_at": "2026-10-10T14:00:00.000Z" } ] }With an Idempotency-Key, message i of the batch uses the key <key>:<i>, so repeating the whole request accepts nothing twice; the repeated results carry "replayed": true. A test token's results carry "test": true.
| Status | When |
|---|---|
| 202 | At least one message was accepted. Check every result. |
| 400 | invalid_json, invalid_request (no messages, or more than 50), invalid_idempotency_key |
| 401 | invalid_token, token_expired |
| 403 | token_blocked, insufficient_scope |
| 413 | payload_too_large: the whole batch counts against the body limit. |
| 422 | No message was accepted; each result says why. |
| 429 | rate_limited |
GET /v1/messages#
/v1/messagesread permissionThe token's own messages, newest first.
| Query | Meaning |
|---|---|
limit | 1 to 100, default 20. |
status | Only this status: queued, , sent, failed or dead. |
before | The next_before of the previous page. |
The answer is { "data": [ ... ], "next_before": "msg_..." }, each message as GET /v1/messages/{id} shows it. next_before is null on the last page.
GET /v1/messages/{id}/events#
/v1/messages/{id}/eventsread permissionWhat happened to a message after it was sent, oldest first, at most 100 events.
{ "data": [ { "id": "evt_01j9z8x7w6v5t4s3r2q1p0n9m8", "type": "message.delivered", "at": "2026-10-10T14:00:03.000Z", "recipient": "guest@example.com", "reason": null } ] }type | Meaning |
|---|---|
message.delivered | The recipient's mail server accepted it. |
message.deferred | The mail server put it off for now (a soft bounce); the mail system keeps trying. |
message.bounced | The address does not exist or refuses mail for good. It goes on the do-not-mail list. |
message.blocked | The mail system or the receiving server blocked it. |
message.complained | The recipient marked it as spam. The address goes on the do-not-mail list. |
message.unsubscribed | The recipient unsubscribed. The address goes on the do-not-mail list. |
message.opened | It was opened (mail apps that load images in advance count too). |
message.clicked | A link in it was clicked. |
message.canceled | It was cancelled before its scheduled time. |
message.cancel_failed | A cancel came too late: it had already gone out. |
A token whose mail keeps bouncing is blocked automatically: once a UTC day has at least 5 bounced or complained messages from it and they are at least 10% of what it sent that day, it answers 403 token_blocked until the hotel unblocks it.
POST /v1/messages/{id}/cancel#
/v1/messages/{id}/cancelsend permissionCancels a message sent with scheduled_at whose time has not come. No body.
| Status | When |
|---|---|
| 200 | { id, status: "failed", canceled_at, cancel: "done" }: it will never be sent. Its error reads "Cancelled before its scheduled time." |
| 202 | cancel: "requested": the mail system already holds it. It is withdrawn within about a minute and then turns failed; if it had already gone out it stays sent with a message.cancel_failed event. |
| 401 | invalid_token, token_expired |
| 403 | token_blocked, insufficient_scope |
| 404 | not_found |
| 409 | not_cancelable: not scheduled, its time has come, already sent or cancelled, or sent by a test token. |
Webhooks#
The hotel can give your app a webhook address (https://, on a public host name) and choose which delivery events it receives (all of them by default, except the cancel ones). Each event is a POST with a JSON body:
{ "type": "message.bounced", "timestamp": "2026-10-10T14:00:03.000Z", "data": { "message_id": "msg_01j9z8x7w6v5t4s3r2q1p0n9m8", "recipient": "guest@example.com", "reason": "mailbox does not exist" } }It is signed the Standard Webhooks way, so any of their libraries can check it.
| Header | Value |
|---|---|
webhook-id | The event id. The same on every retry of the same event: use it to ignore a repeat. |
webhook-timestamp | Seconds since 1970. Reject one more than 5 minutes old. |
webhook-signature | v1, then base64 of HMAC-SHA256 over <webhook-id>.<webhook-timestamp>.<body>, keyed with the base64-decoded bytes after whsec_ in your secret. |
The secret (whsec_...) is shown once, when the hotel sets the address or makes a new secret. Answer with any 2xx within 5 seconds. Anything else, a redirect or a timeout is tried again over about six hours; after the last try the event is marked as failed on the message. The hotel can send a message.test event to check your endpoint.
For recipients: About this email#
/v1/about/{id}no token/v1/about/{id}/reportno tokenEvery message sent through the API ends with a short footer linking to About this email (/about/?m=<message id>), a page for the person who received it. That page uses these two endpoints; integrations do not need them.
GET /v1/about/{id}answersid,status,from,created_atandsent_at: only what the email itself shows, never the recipients, the subject or the body.POST /v1/about/{id}/reporttakes{"reason": "unexpected" | "unwanted" | "fraud"}and answers 202. The hotel sees the report next to your token in its activity trail; nothing about the person reporting is kept.- Both are limited per address at the edge (429
rate_limited), and an unknown id answers 404not_found.
The footer is added when the message is sent, after your content, in both the HTML and the text part. GET /v1/messages/{id} and your stored copy do not include it.
Errors#
Every error is a problem document. Switch on code; show detail to a person; quote request_id when you ask for help.
{
"type": "about:blank",
"title": "Unprocessable request",
"status": 422,
"detail": "This Idempotency-Key was already used with a different request body.",
"code": "idempotency_key_reuse",
"request_id": "a4389ca6781df288"
}The full list, with what to do for each, is on the Errors page.
Last reviewed 2026-10-01.