# Message templates

Reusable templates for emails and text messages

Endpoint: `https://api.bookingmood.com/v1/message_templates`, supporting `GET`, `POST`, `DELETE`, `PATCH`. Authenticate with the header `Authorization: Bearer YOUR_API_KEY` (see [authentication](https://www.bookingmood.com/ja-JP/api-reference/authentication.md)).

## The message template object

| Attribute | Type | Description |
| --- | --- | --- |
| `id` | `uuid` | Unique identifier. |
| `organization_id` | `uuid` | Identifier of the organization this message template is defined in. References [`organizations.id`](https://www.bookingmood.com/ja-JP/api-reference/organizations.md). |
| `created_at` | `timestamp with time zone` | Creation timestamp. Read-only: set by the database. |
| `updated_at` | `timestamp with time zone` | Last modification timestamp. Read-only: set by the database. |
| `attachments` | `Array<MessageAttachment>` | Attachments to include in the email. |
| `body` | `MultiLanguageString` | Localized body of the message. |
| `fts` | `tsvector` | Full text search index. Read-only: set by the database. |
| `include_booking_details` | `boolean` | Whether to include booking details in the message. |
| `include_booking_link` | `boolean` | Whether to include a link to the guest page in the message. |
| `include_ical_data` | `boolean` | Whether to include an iCal attachment in the email. |
| `include_product_image` | `boolean` | Whether to include an image of the unit in the email. |
| `include_transactions` | `boolean` | Whether to include the booking's transactions in the message. |
| `moment` | `MessageMoment \| null` | Moment at which the message is sent. |
| `past_schedule_behavior` | `MessagePastScheduleBehavior` | What happens when a message is created with a moment in the past. |
| `status` | `MessageTemplateStatus` | Whether messages are scheduled for pending and confirmed events, or for confirmed events only. |
| `subject` | `MultiLanguageString` | Localized subject of the email. |
| `time` | `time without time zone \| null` | Time of day at which the message is sent. |
| `trigger` | `MessageTrigger \| null` | Trigger of the message template. |
| `type` | `MessageType` | Type of the message: `email` or `sms`. |

```json
{
  "id": "00000000-0000-0000-0000-000000000000",
  "organization_id": "00000000-0000-0000-0000-000000000000",
  "created_at": "2026-10-30T23:18:45.588Z",
  "updated_at": "2026-10-30T23:18:45.588Z",
  "attachments": [
    {
      "filename": "file",
      "url": "https://example.com",
      "type": "application/pdf"
    }
  ],
  "body": {},
  "include_booking_details": false,
  "include_booking_link": true,
  "include_ical_data": false,
  "include_product_image": false,
  "include_transactions": false,
  "moment": {
    "offset": 1,
    "type": "check-in"
  },
  "past_schedule_behavior": "send",
  "status": "CONFIRMED",
  "subject": {},
  "time": null,
  "trigger": "all-payments-completed",
  "type": "email"
}
```

### Types

```typescript
type Language = 
  | "be-BY"
  | "bg-BG"
  | "cs-CZ"
  | "da-DK"
  | "de-DE"
  | "en-GB"
  | "en-NZ"
  | "en-US"
  | "es-ES"
  | "eu-ES"
  | "fr-FR"
  | "gr-EL"
  | "he-IL"
  | "hr-HR"
  | "hu-HU"
  | "it-IT"
  | "ja-JP"
  | "lt-LT"
  | "lv-LV"
  | "nl-NL"
  | "nn-NO"
  | "pl-PL"
  | "pt-BR"
  | "ro-RO"
  | "ru-RU"
  | "sk-SK"
  | "sl-SI"
  | "sr-Cyrl"
  | "sr-Latn"
  | "sv-SE"
  | "tr-TR"
  | "uk-UA";

type MessageAttachment = {
  filename: string;
  type: string;
  url: string;
};

type MessageMoment = {
  offset: number;
  type: "check-in" | "checkout";
};

type MessagePastScheduleBehavior = "skip" | "send";

type MessageTemplateStatus = "TENTATIVE" | "CONFIRMED";

type MessageTrigger = 
  | "booking-updated"
  | "booking-request-received"
  | "direct-booking-received"
  | "booking-request-confirmed"
  | "booking-request-pending"
  | "booking-request-rejected"
  | "invoice-created"
  | "payment-due"
  | "payment-received"
  | "all-payments-completed";

type MessageType = "email" | "sms";

type MultiLanguageString = {
  default: string;
} & Partial<Record<Language, string>>;
```

### Related resources

Embed related resources with the [`select` parameter](https://www.bookingmood.com/ja-JP/api-reference/selecting.md), e.g. `select=*,organizations(*)`. Resources related through more than one column need the column as a hint, like `table!column(*)`.

| Embed | Type | Description |
| --- | --- | --- |
| `organizations(*)` | `object \| null` | The [organization](https://www.bookingmood.com/ja-JP/api-reference/organizations.md) referenced by `organization_id`. |
| `messages(*)` | `array` | The [messages](https://www.bookingmood.com/ja-JP/api-reference/messages.md) referencing this message template through `messages.message_template_id`. |
| `product_message_templates(*)` | `array` | The [product message templates](https://www.bookingmood.com/ja-JP/api-reference/product_message_templates.md) referencing this message template through `product_message_templates.message_template_id`. |

## List message templates

`GET /v1/message_templates`

Filter on any attribute with `column=operator.value` (see [filtering](https://www.bookingmood.com/ja-JP/api-reference/filtering.md)). Choose columns and embed related resources with `select` (see [selecting](https://www.bookingmood.com/ja-JP/api-reference/selecting.md)), and sort and paginate with `order`, `limit` and `offset` (see [sorting and pagination](https://www.bookingmood.com/ja-JP/api-reference/sorting-pagination.md)).

```bash
curl -X GET "https://api.bookingmood.com/v1/message_templates?select=*&limit=10" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

Responses:

- `200`: A list of message templates with the selected columns. `206` when the list is a partial range.
- `400`: The request is malformed, for example an unknown column or an invalid filter.
- `401`: The API key is missing or invalid.

## Create message templates

`POST /v1/message_templates`

Insert one message template or an array of message templates. The body is a `Partial` message template object, so columns with a default can be left out. Read-only attributes can't be written.

```bash
curl -X POST "https://api.bookingmood.com/v1/message_templates" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "organization_id": "00000000-0000-0000-0000-000000000000",
    "attachments": [
      {
        "filename": "file",
        "url": "https://example.com",
        "type": "application/pdf"
      }
    ],
    "body": {},
    "include_booking_details": false,
    "include_booking_link": true,
    "include_ical_data": false,
    "include_product_image": false,
    "include_transactions": false,
    "past_schedule_behavior": "send",
    "status": "CONFIRMED",
    "subject": {},
    "type": "email"
  }'
```

Responses:

- `201`: The newly created message templates with the selected columns.
- `400`: The request is malformed, for example an unknown column, an invalid filter or an invalid body.
- `401`: The API key is missing or invalid.
- `403`: The API key has no permission for this change, for example when writing rows of another organization.
- `409`: The change conflicts with existing data, for example a duplicate key or a reference to a row that does not exist.

## Delete message templates

`DELETE /v1/message_templates`

Filter on any attribute with `column=operator.value` (see [filtering](https://www.bookingmood.com/ja-JP/api-reference/filtering.md)). Without filters, this request deletes all message templates you have access to. Always filter on at least one column, e.g. `id=eq.{id}`.

```bash
curl -X DELETE "https://api.bookingmood.com/v1/message_templates?id=eq.00000000-0000-0000-0000-000000000000" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

Responses:

- `200`: The deleted message templates with the selected columns. `204` without a body when sending the header `Prefer: return=minimal`.
- `400`: The request is malformed, for example an unknown column or an invalid filter.
- `401`: The API key is missing or invalid.
- `403`: The API key has no permission for this change, for example when writing rows of another organization.

## Update message templates

`PATCH /v1/message_templates`

Filter on any attribute with `column=operator.value` (see [filtering](https://www.bookingmood.com/ja-JP/api-reference/filtering.md)). Without filters, this request updates all message templates you have access to. Always filter on at least one column, e.g. `id=eq.{id}`. The body holds the attributes to change.

```bash
curl -X PATCH "https://api.bookingmood.com/v1/message_templates?id=eq.00000000-0000-0000-0000-000000000000" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "attachments": [
      {
        "filename": "file",
        "url": "https://example.com",
        "type": "application/pdf"
      }
    ]
  }'
```

Responses:

- `200`: The updated message templates with the selected columns. `204` without a body when sending the header `Prefer: return=minimal`.
- `400`: The request is malformed, for example an unknown column, an invalid filter or an invalid body.
- `401`: The API key is missing or invalid.
- `403`: The API key has no permission for this change, for example when writing rows of another organization.
- `409`: The change conflicts with existing data, for example a duplicate key or a reference to a row that does not exist.

Errors have a JSON body with a `code`, `message`, `details` and `hint`. See the [introduction](https://www.bookingmood.com/ja-JP/api-reference.md) for more on errors. The full API is described by the OpenAPI spec at https://api.bookingmood.com/v1/openapi.json.
