{
  "openapi": "3.1.0",
  "info": {
    "title": "Madagascar Email API",
    "version": "1.0.0",
    "summary": "Send the hotel's transactional email from your own code.",
    "description": "A REST API over HTTPS. Requests and responses are JSON; errors are RFC 9457 problem documents with a stable `code`. Sending is asynchronous: `POST /v1/messages` answers 202 Accepted and the message is delivered by a separate worker. Human documentation: https://email.madagascarhotelags.com",
    "contact": {
      "name": "Madagascar Pet Hotel AGS",
      "email": "team@madagascarhotelags.com",
      "url": "https://email.madagascarhotelags.com"
    },
    "termsOfService": "https://email.madagascarhotelags.com/policies/terms/"
  },
  "servers": [
    {
      "url": "https://email.madagascarhotelags.com",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerToken": []
    }
  ],
  "tags": [
    {
      "name": "Messages",
      "description": "Send messages one at a time or in batches, list them, read their status and delivery events, and cancel a scheduled one."
    },
    {
      "name": "Token",
      "description": "The calling token's identity and usage."
    },
    {
      "name": "Templates",
      "description": "Stored templates the hotel publishes: send one by id with variables instead of writing the content."
    },
    {
      "name": "Attachments",
      "description": "Files to attach to a message: uploaded first, checked as they arrive, and ready to send at once."
    },
    {
      "name": "Service",
      "description": "Health."
    },
    {
      "name": "Recipients",
      "description": "For people who received an email: the footer link of every message leads to these, without a token."
    }
  ],
  "paths": {
    "/v1/health": {
      "get": {
        "operationId": "getHealth",
        "tags": [
          "Service"
        ],
        "summary": "Check that the API is up",
        "security": [],
        "responses": {
          "200": {
            "description": "The API is up.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Health"
                }
              }
            }
          }
        }
      }
    },
    "/v1/me": {
      "get": {
        "operationId": "getMe",
        "tags": [
          "Token"
        ],
        "summary": "The calling token's permissions, senders, limits and usage",
        "responses": {
          "200": {
            "description": "The token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Me"
                }
              }
            }
          },
          "401": {
            "description": "No usable token. Codes: invalid_token, token_expired.",
            "headers": {
              "WWW-Authenticate": {
                "$ref": "#/components/headers/WwwAuthenticate"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The token is blocked, its client is paused, or the call came from outside its address allow-list. Codes: token_blocked, insufficient_scope, client_paused, ip_not_allowed, template_not_allowed, templates_only, recipient_not_allowed, sender_not_allowed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "The API is switched off or not fully configured. Codes: api_disabled, unavailable, attachments_unavailable.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages": {
      "get": {
        "operationId": "listMessages",
        "tags": [
          "Messages"
        ],
        "summary": "List the token's messages, newest first",
        "description": "Needs the `read` permission. Pass `next_before` as `before` to get the next page.",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 100,
              "default": 20
            }
          },
          {
            "name": "before",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^msg_[0-9a-z]{26}$"
            }
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "$ref": "#/components/schemas/Status"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of messages.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/MessageList"
                }
              }
            }
          },
          "400": {
            "description": "A query parameter is invalid. Codes: invalid_json, invalid_request, unknown_field, invalid_address, too_many_recipients, invalid_schedule, invalid_idempotency_key.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "No usable token. Codes: invalid_token, token_expired.",
            "headers": {
              "WWW-Authenticate": {
                "$ref": "#/components/headers/WwwAuthenticate"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The token may not read. Codes: token_blocked, insufficient_scope, client_paused, ip_not_allowed, template_not_allowed, templates_only, recipient_not_allowed, sender_not_allowed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "sendMessage",
        "tags": [
          "Messages"
        ],
        "summary": "Send a message",
        "description": "Needs the `send` permission. Answers 202 once the message is stored and queued.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MessageRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Accepted and queued, or the replay of an earlier request with the same Idempotency-Key.",
            "headers": {
              "Location": {
                "description": "Path of the message.",
                "schema": {
                  "type": "string",
                  "example": "/v1/messages/msg_01k6qzexample0000000000000"
                }
              },
              "Idempotent-Replayed": {
                "description": "`true` when this answer repeats an earlier one.",
                "schema": {
                  "type": "string",
                  "enum": [
                    "true"
                  ]
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Accepted"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. Codes: invalid_json, invalid_request, unknown_field, invalid_address, too_many_recipients, invalid_schedule, invalid_idempotency_key.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "No usable token. Codes: invalid_token, token_expired.",
            "headers": {
              "WWW-Authenticate": {
                "$ref": "#/components/headers/WwwAuthenticate"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The token may not do this. Codes: token_blocked, insufficient_scope, client_paused, ip_not_allowed, template_not_allowed, templates_only, recipient_not_allowed, sender_not_allowed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "405": {
            "description": "Wrong method. Codes: method_not_allowed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "The body is over 256 KiB. Codes: payload_too_large.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "415": {
            "description": "Content-Type is not application/json. Codes: unsupported_media_type.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "The Idempotency-Key was used with another body, the template is not published, the variables do not fit it, or the content check refused the message. Codes: idempotency_key_reuse, unknown_template, invalid_variables, content_blocked, attachment_not_found, attachment_refused, attachments_too_large.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "A limit was reached. Codes: rate_limited, daily_cap_reached, monthly_cap_reached, api_budget_reached.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "500": {
            "description": "Unexpected fault. Codes: internal.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Switched off or temporarily unavailable. Codes: api_disabled, unavailable, attachments_unavailable.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/batch": {
      "post": {
        "operationId": "sendBatch",
        "tags": [
          "Messages"
        ],
        "summary": "Send up to 50 messages in one request",
        "description": "Needs the `send` permission. Each message is checked and counted against every limit as if sent alone, and accepted or refused on its own; `results` lists them in order. With an Idempotency-Key, message i uses `<key>:<i>`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/IdempotencyKey"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "messages"
                ],
                "properties": {
                  "messages": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 50,
                    "items": {
                      "$ref": "#/components/schemas/MessageRequest"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "At least one message was accepted.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchResult"
                }
              }
            }
          },
          "400": {
            "description": "The request is invalid. Codes: invalid_json, invalid_request, unknown_field, invalid_address, too_many_recipients, invalid_schedule, invalid_idempotency_key.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "No usable token. Codes: invalid_token, token_expired.",
            "headers": {
              "WWW-Authenticate": {
                "$ref": "#/components/headers/WwwAuthenticate"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The token may not send. Codes: token_blocked, insufficient_scope, client_paused, ip_not_allowed, template_not_allowed, templates_only, recipient_not_allowed, sender_not_allowed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "The body is over 256 KiB. Codes: payload_too_large.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "415": {
            "description": "Content-Type is not application/json. Codes: unsupported_media_type.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Every message was refused; `results` says why for each.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BatchResult"
                }
              }
            }
          },
          "503": {
            "description": "Switched off or temporarily unavailable. Codes: api_disabled, unavailable, attachments_unavailable.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/{id}/events": {
      "get": {
        "operationId": "listMessageEvents",
        "tags": [
          "Messages"
        ],
        "summary": "What happened to a message: delivered, bounced, opened, clicked, cancelled",
        "description": "Needs the `read` permission. Oldest first, at most 100.",
        "parameters": [
          {
            "$ref": "#/components/parameters/MessageId"
          }
        ],
        "responses": {
          "200": {
            "description": "The events.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EventList"
                }
              }
            }
          },
          "401": {
            "description": "No usable token. Codes: invalid_token, token_expired.",
            "headers": {
              "WWW-Authenticate": {
                "$ref": "#/components/headers/WwwAuthenticate"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The token may not read. Codes: token_blocked, insufficient_scope, client_paused, ip_not_allowed, template_not_allowed, templates_only, recipient_not_allowed, sender_not_allowed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "No such message for this token. Codes: not_found.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/{id}/cancel": {
      "post": {
        "operationId": "cancelMessage",
        "tags": [
          "Messages"
        ],
        "summary": "Cancel a scheduled message before its time",
        "description": "Needs the `send` permission. 200 when it is cancelled; 202 when the mail system already holds it and has been asked to drop it (`cancel: \"requested\"`; the message turns `failed` once it has).",
        "parameters": [
          {
            "$ref": "#/components/parameters/MessageId"
          }
        ],
        "responses": {
          "200": {
            "description": "Cancelled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Cancelled"
                }
              }
            }
          },
          "202": {
            "description": "Cancel requested from the mail system.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Cancelled"
                }
              }
            }
          },
          "401": {
            "description": "No usable token. Codes: invalid_token, token_expired.",
            "headers": {
              "WWW-Authenticate": {
                "$ref": "#/components/headers/WwwAuthenticate"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The token may not send. Codes: token_blocked, insufficient_scope, client_paused, ip_not_allowed, template_not_allowed, templates_only, recipient_not_allowed, sender_not_allowed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "No such message for this token. Codes: not_found.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "409": {
            "description": "It cannot be cancelled. Codes: not_cancelable.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Temporarily unavailable. Codes: api_disabled, unavailable, attachments_unavailable.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/attachments": {
      "post": {
        "operationId": "uploadAttachment",
        "tags": [
          "Attachments"
        ],
        "summary": "Upload a file to attach to a message",
        "description": "Needs the `send` permission. The body is the file itself (not JSON), with its `Content-Type` and `Content-Length`; `filename` names it. At most 4000000 bytes, of the types pdf, png, jpg, jpeg, gif, txt, csv, ics, doc, docx, xls, xlsx, ppt, pptx, odt, ods, rtf, zip. The file is checked as it arrives: its contents must be the type its name says, and programs, scripts, macros, embedded files and password-protected files are refused with `attachment_refused`. A file that passes is `clean` and can be sent at once. It is kept 24 hours, and only this token can use it.",
        "parameters": [
          {
            "name": "filename",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "minLength": 1,
              "maxLength": 100
            },
            "description": "The name the recipient sees, with its extension."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "*/*": {
              "schema": {
                "type": "string",
                "format": "binary"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Checked and stored, ready to send.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Attachment"
                }
              }
            }
          },
          "400": {
            "description": "A bad file name or type. Codes: invalid_json, invalid_request, unknown_field, invalid_address, too_many_recipients, invalid_schedule, invalid_idempotency_key.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "401": {
            "description": "No usable token. Codes: invalid_token, token_expired.",
            "headers": {
              "WWW-Authenticate": {
                "$ref": "#/components/headers/WwwAuthenticate"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The token may not send. Codes: token_blocked, insufficient_scope, client_paused, ip_not_allowed, template_not_allowed, templates_only, recipient_not_allowed, sender_not_allowed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "411": {
            "description": "No Content-Length. Codes: length_required.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "The file is too large. Codes: payload_too_large.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "The check refused the file; `detail` says why. Codes: idempotency_key_reuse, unknown_template, invalid_variables, content_blocked, attachment_not_found, attachment_refused, attachments_too_large.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Attachments are not available right now. Codes: api_disabled, unavailable, attachments_unavailable.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/attachments/{id}": {
      "get": {
        "operationId": "getAttachment",
        "tags": [
          "Attachments"
        ],
        "summary": "Read an uploaded file",
        "description": "Needs the `send` permission. Files of other tokens, and expired files, answer 404.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^att_[0-9a-z]{26}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The file.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Attachment"
                }
              }
            }
          },
          "401": {
            "description": "No usable token. Codes: invalid_token, token_expired.",
            "headers": {
              "WWW-Authenticate": {
                "$ref": "#/components/headers/WwwAuthenticate"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The token may not send. Codes: token_blocked, insufficient_scope, client_paused, ip_not_allowed, template_not_allowed, templates_only, recipient_not_allowed, sender_not_allowed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "No such file for this token. Codes: not_found.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Attachments are not available right now. Codes: api_disabled, unavailable, attachments_unavailable.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/templates": {
      "get": {
        "operationId": "listTemplates",
        "tags": [
          "Templates"
        ],
        "summary": "The published templates and the variables each one takes",
        "description": "Needs the `send` permission. Only published, active templates are listed.",
        "responses": {
          "200": {
            "description": "The templates.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TemplateList"
                }
              }
            }
          },
          "401": {
            "description": "No usable token. Codes: invalid_token, token_expired.",
            "headers": {
              "WWW-Authenticate": {
                "$ref": "#/components/headers/WwwAuthenticate"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The token may not send. Codes: token_blocked, insufficient_scope, client_paused, ip_not_allowed, template_not_allowed, templates_only, recipient_not_allowed, sender_not_allowed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "503": {
            "description": "Switched off or temporarily unavailable. Codes: api_disabled, unavailable, attachments_unavailable.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/{id}": {
      "get": {
        "operationId": "getMessage",
        "tags": [
          "Messages"
        ],
        "summary": "Read a message sent with the same token",
        "description": "Needs the `read` permission. Messages of other tokens answer 404.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^msg_[0-9a-z]{26}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Message"
                }
              }
            }
          },
          "401": {
            "description": "No usable token. Codes: invalid_token, token_expired.",
            "headers": {
              "WWW-Authenticate": {
                "$ref": "#/components/headers/WwwAuthenticate"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "403": {
            "description": "The token may not do this. Codes: token_blocked, insufficient_scope, client_paused, ip_not_allowed, template_not_allowed, templates_only, recipient_not_allowed, sender_not_allowed.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "No such message for this token. Codes: not_found.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/about/{id}": {
      "get": {
        "operationId": "getAbout",
        "tags": [
          "Recipients"
        ],
        "summary": "What the recipient of a message may know about it",
        "description": "No token. Only what the email itself shows: the sender, the status and the dates; never the recipients, the subject or the body.",
        "security": [],
        "parameters": [
          {
            "$ref": "#/components/parameters/MessageId"
          }
        ],
        "responses": {
          "200": {
            "description": "The message, as its recipient sees it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/About"
                }
              }
            }
          },
          "404": {
            "description": "No such message. Codes: not_found.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests from this address. Codes: rate_limited, daily_cap_reached, monthly_cap_reached, api_budget_reached.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/v1/about/{id}/report": {
      "post": {
        "operationId": "reportMessage",
        "tags": [
          "Recipients"
        ],
        "summary": "Report a message you received",
        "description": "No token. The hotel sees the report with the message id and the reason; nothing about the person reporting is kept.",
        "security": [],
        "parameters": [
          {
            "$ref": "#/components/parameters/MessageId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "reason"
                ],
                "properties": {
                  "reason": {
                    "type": "string",
                    "enum": [
                      "unexpected",
                      "unwanted",
                      "fraud"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "The report was received.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "received": {
                      "const": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The body is not a valid report. Codes: invalid_json, invalid_request, unknown_field, invalid_address, too_many_recipients, invalid_schedule, invalid_idempotency_key.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "404": {
            "description": "No such message. Codes: not_found.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "413": {
            "description": "The body is too large. Codes: payload_too_large.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "415": {
            "description": "Not JSON. Codes: unsupported_media_type.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Too many requests from this address. Codes: rate_limited, daily_cap_reached, monthly_cap_reached, api_budget_reached.",
            "headers": {
              "Retry-After": {
                "$ref": "#/components/headers/RetryAfter"
              }
            },
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerToken": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "ems_<12 characters>_<40 characters> (ems_test_... for a test token)",
        "description": "A token issued by the hotel. Send it as `Authorization: Bearer <token>` (RFC 6750)."
      }
    },
    "headers": {
      "RetryAfter": {
        "description": "Seconds to wait before retrying.",
        "schema": {
          "type": "integer",
          "minimum": 1
        }
      },
      "WwwAuthenticate": {
        "description": "The authentication scheme.",
        "schema": {
          "type": "string",
          "enum": [
            "Bearer"
          ]
        }
      }
    },
    "parameters": {
      "MessageId": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "pattern": "^msg_[0-9a-z]{26}$"
        }
      },
      "IdempotencyKey": {
        "name": "Idempotency-Key",
        "in": "header",
        "required": false,
        "description": "Makes retries safe: the same key with the same body returns the first answer; with another body, 422.",
        "schema": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.:-]{1,128}$"
        }
      }
    },
    "schemas": {
      "Address": {
        "description": "An email address, optionally with a display name: \"user@example.com\" or \"Name <user@example.com>\".",
        "type": "string",
        "minLength": 3,
        "examples": [
          "guest@example.com",
          "Ana López <guest@example.com>"
        ]
      },
      "Sender": {
        "oneOf": [
          {
            "$ref": "#/components/schemas/Address"
          },
          {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "email"
            ],
            "properties": {
              "email": {
                "type": "string",
                "format": "email"
              },
              "name": {
                "type": "string",
                "maxLength": 100
              }
            }
          }
        ]
      },
      "MessageRequest": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "to"
        ],
        "description": "Either `subject` with at least one of `html` and `text`, or `template_id` (with its `variables` and an optional `locale`), never both. `to`, `cc` and `bcc` together are limited per message (10 unless the hotel set otherwise, at most 50).",
        "properties": {
          "to": {
            "type": "array",
            "minItems": 1,
            "items": {
              "$ref": "#/components/schemas/Address"
            }
          },
          "cc": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Address"
            }
          },
          "bcc": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Address"
            }
          },
          "from": {
            "$ref": "#/components/schemas/Sender"
          },
          "reply_to": {
            "$ref": "#/components/schemas/Address"
          },
          "subject": {
            "type": "string",
            "minLength": 1,
            "maxLength": 998
          },
          "html": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200000
          },
          "text": {
            "type": "string",
            "minLength": 1,
            "maxLength": 100000
          },
          "tags": {
            "type": "array",
            "maxItems": 5,
            "items": {
              "type": "string",
              "pattern": "^[A-Za-z0-9_-]{1,32}$"
            }
          },
          "scheduled_at": {
            "type": "string",
            "format": "date-time",
            "description": "Between 1 minute and 72 hours from now."
          },
          "template_id": {
            "type": "string",
            "pattern": "^tpl_[a-z0-9_]{2,60}$",
            "description": "A published template (see `GET /v1/templates`). The subject and content come from it."
          },
          "variables": {
            "type": "object",
            "additionalProperties": true,
            "description": "The values the template declares, by name. Each is checked against its declared type."
          },
          "locale": {
            "type": "string",
            "pattern": "^[a-z]{2}$",
            "description": "The language to use (`es` or `en`). Without it, or when the template lacks it: Spanish, else the language it has."
          },
          "attachments": {
            "type": "array",
            "minItems": 1,
            "maxItems": 3,
            "description": "Files uploaded with `POST /v1/attachments` by this token, 4000000 bytes together at most. An expired file, or another token's, answers `attachment_not_found`.",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "id"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "pattern": "^att_[0-9a-z]{26}$"
                }
              }
            }
          }
        }
      },
      "Attachment": {
        "type": "object",
        "required": [
          "id",
          "filename",
          "bytes",
          "status",
          "expires_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^att_[0-9a-z]{26}$"
          },
          "filename": {
            "type": "string"
          },
          "bytes": {
            "type": "integer"
          },
          "content_type": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "clean"
            ],
            "description": "Every stored file passed the check at upload; a refused file is never stored."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "expires_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "TemplateList": {
        "type": "object",
        "required": [
          "templates"
        ],
        "properties": {
          "templates": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "name",
                "description",
                "version",
                "locales",
                "variables"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "version": {
                  "type": "integer",
                  "description": "The published version that a send uses now."
                },
                "locales": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": [
                      "es",
                      "en"
                    ]
                  }
                },
                "variables": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": [
                      "name",
                      "type",
                      "required"
                    ],
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "type": {
                        "type": "string",
                        "enum": [
                          "string",
                          "number",
                          "boolean",
                          "date",
                          "url",
                          "email",
                          "html",
                          "list"
                        ]
                      },
                      "required": {
                        "type": "boolean"
                      },
                      "description": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      },
      "Status": {
        "type": "string",
        "enum": [
          "queued",
          "retrying",
          "sent",
          "failed",
          "dead"
        ]
      },
      "Accepted": {
        "type": "object",
        "required": [
          "id",
          "status",
          "created_at"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^msg_[0-9a-z]{26}$"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "test": {
            "type": "boolean",
            "description": "Present and true when a test token sent it: checked and recorded, never sent."
          }
        }
      },
      "Message": {
        "type": "object",
        "required": [
          "id",
          "status",
          "from",
          "to",
          "cc_count",
          "bcc_count",
          "subject",
          "created_at",
          "attempt",
          "suppressed"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "from": {
            "type": "string"
          },
          "to": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "cc_count": {
            "type": "integer"
          },
          "bcc_count": {
            "type": "integer"
          },
          "subject": {
            "type": "string"
          },
          "scheduled_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "sent_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "attempt": {
            "type": "integer"
          },
          "error": {
            "type": [
              "string",
              "null"
            ],
            "description": "Why, for failed and dead messages. Human text, not a code."
          },
          "delivery": {
            "type": [
              "string",
              "null"
            ],
            "enum": [
              "delivered",
              "deferred",
              "bounced",
              "blocked",
              "complained",
              "unsubscribed",
              null
            ],
            "description": "The mail system's latest verdict once the message was handed over; null until one arrives. The events list has every step."
          },
          "delivery_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "suppressed": {
            "type": "integer",
            "description": "Recipients removed by the suppression list."
          },
          "test": {
            "type": "boolean",
            "description": "True for a message a test token sent: recorded, never sent."
          },
          "canceled_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time",
            "description": "When it was cancelled; null when it was not."
          }
        }
      },
      "MessageList": {
        "type": "object",
        "required": [
          "data",
          "next_before"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Message"
            }
          },
          "next_before": {
            "type": [
              "string",
              "null"
            ],
            "description": "Pass as `before` for the next page; null on the last page."
          }
        }
      },
      "BatchResult": {
        "type": "object",
        "required": [
          "accepted",
          "refused",
          "results"
        ],
        "properties": {
          "accepted": {
            "type": "integer"
          },
          "refused": {
            "type": "integer"
          },
          "results": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "index"
              ],
              "properties": {
                "index": {
                  "type": "integer"
                },
                "id": {
                  "type": "string"
                },
                "status": {
                  "$ref": "#/components/schemas/Status"
                },
                "created_at": {
                  "type": "string",
                  "format": "date-time"
                },
                "test": {
                  "type": "boolean"
                },
                "replayed": {
                  "type": "boolean",
                  "description": "An earlier batch with the same Idempotency-Key already accepted it."
                },
                "error": {
                  "type": "object",
                  "properties": {
                    "code": {
                      "type": "string"
                    },
                    "detail": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      },
      "EventList": {
        "type": "object",
        "required": [
          "data"
        ],
        "properties": {
          "data": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "id",
                "type",
                "at"
              ],
              "properties": {
                "id": {
                  "type": "string"
                },
                "type": {
                  "type": "string",
                  "enum": [
                    "message.delivered",
                    "message.deferred",
                    "message.bounced",
                    "message.blocked",
                    "message.complained",
                    "message.unsubscribed",
                    "message.opened",
                    "message.clicked",
                    "message.canceled",
                    "message.cancel_failed"
                  ]
                },
                "at": {
                  "type": "string",
                  "format": "date-time"
                },
                "recipient": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "reason": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              }
            }
          }
        }
      },
      "Cancelled": {
        "type": "object",
        "required": [
          "id",
          "status",
          "canceled_at",
          "cancel"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/Status"
          },
          "canceled_at": {
            "type": "string",
            "format": "date-time"
          },
          "cancel": {
            "type": "string",
            "enum": [
              "done",
              "requested"
            ]
          }
        }
      },
      "Me": {
        "type": "object",
        "required": [
          "token",
          "usage",
          "api"
        ],
        "properties": {
          "token": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "mode": {
                "type": "string",
                "enum": [
                  "live",
                  "test"
                ]
              },
              "client": {
                "type": [
                  "string",
                  "null"
                ],
                "description": "The app or service the token belongs to."
              },
              "scopes": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "send",
                    "read"
                  ]
                }
              },
              "senders": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              },
              "templates": {
                "type": [
                  "array",
                  "null"
                ],
                "items": {
                  "type": "string"
                },
                "description": "The templates it may send; null for any published one."
              },
              "templates_only": {
                "type": "boolean",
                "description": "True when it may send templates only."
              },
              "rate_per_min": {
                "type": "integer"
              },
              "daily_cap": {
                "type": "integer"
              },
              "monthly_cap": {
                "type": [
                  "integer",
                  "null"
                ],
                "description": "Messages a UTC calendar month; null for no limit."
              },
              "expires_at": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date-time"
              }
            }
          },
          "usage": {
            "type": "object",
            "properties": {
              "sent_today": {
                "type": "integer"
              },
              "remaining_today": {
                "type": "integer"
              },
              "sent_this_month": {
                "type": "integer"
              },
              "remaining_this_month": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            }
          },
          "api": {
            "type": "object",
            "properties": {
              "enabled": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "About": {
        "type": "object",
        "required": [
          "id",
          "status",
          "from",
          "created_at",
          "sent_at"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "sent",
              "retrying",
              "failed",
              "dead"
            ]
          },
          "from": {
            "type": "string",
            "format": "email"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "sent_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "Health": {
        "type": "object",
        "required": [
          "ok",
          "service",
          "time"
        ],
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "service": {
            "type": "string"
          },
          "time": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details, plus a stable `code` and a `request_id`.",
        "required": [
          "type",
          "title",
          "status",
          "detail",
          "code",
          "request_id"
        ],
        "properties": {
          "type": {
            "type": "string",
            "example": "about:blank"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string",
            "enum": [
              "invalid_json",
              "invalid_request",
              "unknown_field",
              "invalid_address",
              "too_many_recipients",
              "invalid_schedule",
              "invalid_idempotency_key",
              "invalid_token",
              "token_expired",
              "token_blocked",
              "insufficient_scope",
              "client_paused",
              "ip_not_allowed",
              "template_not_allowed",
              "templates_only",
              "recipient_not_allowed",
              "sender_not_allowed",
              "not_found",
              "method_not_allowed",
              "not_cancelable",
              "length_required",
              "payload_too_large",
              "unsupported_media_type",
              "idempotency_key_reuse",
              "unknown_template",
              "invalid_variables",
              "content_blocked",
              "attachment_not_found",
              "attachment_refused",
              "attachments_too_large",
              "rate_limited",
              "daily_cap_reached",
              "monthly_cap_reached",
              "api_budget_reached",
              "internal",
              "api_disabled",
              "unavailable",
              "attachments_unavailable"
            ]
          },
          "request_id": {
            "type": "string"
          }
        }
      }
    }
  }
}