> ## Documentation Index
> Fetch the complete documentation index at: https://docs.msgflash.com/llms.txt
> Use this file to discover all available pages before exploring further.

# POST Schedule a message

> Schedule a future message in direct mode or with a template.

## Endpoint

```txt theme={null}
POST /api/v1/messages/schedule
```

## Important — how to get `instanceId`

`instanceId` is the technical identifier required to schedule a message.

To get it:

1. call `GET /api/v1/instances`
2. choisir l’instance souhaitée
3. copy `data[n].id`
4. utiliser cette valeur dans `instanceId`

Ne pas envoyer :

* `name`
* `waNumber`

## Body

| Field         | Type     | Required               | Description                                                                                   |
| ------------- | -------- | ---------------------- | --------------------------------------------------------------------------------------------- |
| `instanceId`  | UUID     | yes                    | Technical identifier of the MsgFlash instance, obtained via `GET /api/v1/instances`           |
| `to`          | string   | yes                    | E.164 number                                                                                  |
| `scheduledAt` | ISO 8601 | yes                    | Date/heure d'envoi                                                                            |
| `type`        | enum     | yes if no `templateId` | `text`, `image`, `video`, `audio`, `document`, `voice_note`, `location`, `contact`, `buttons` |
| `templateId`  | UUID     | yes if no `type`       | Template to render                                                                            |
| `variables`   | object   | no                     | `custom.*` values                                                                             |

Les autres champs suivent les mêmes règles que `/messages/send`, y compris les champs spécifiques aux boutons (`title`, `description`, `footer`, `buttons`).

## Request example

```bash theme={null}
curl -X POST https://srv.msgflash.com/api/v1/messages/schedule \
  -H "x-api-key: msgf_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "instanceId": "INSTANCE_UUID",
    "to": "+33612345678",
    "type": "text",
    "text": "Hello dans 30 minutes",
    "scheduledAt": "2026-04-02T08:00:00.000Z"
  }'
```

## Example avec boutons

```bash theme={null}
curl -X POST https://srv.msgflash.com/api/v1/messages/schedule \
  -H "x-api-key: msgf_live_your_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "instanceId": "INSTANCE_UUID",
    "to": "+33612345678",
    "type": "buttons",
    "title": "Rappel programmé",
    "description": "Votre rendez-vous est dans 30 minutes",
    "scheduledAt": "2026-04-02T08:00:00.000Z",
    "buttons": [
      {
        "type": "reply",
        "displayText": "Confirmer",
        "id": "confirm_appointment"
      }
    ]
  }'
```

## Success response `201`

```json theme={null}
{
  "data": {
    "id": "msg_uuid",
    "userId": "user_uuid",
    "instanceId": "inst_uuid",
    "contactId": null,
    "campaignId": null,
    "direction": "outbound",
    "type": "text",
    "from": null,
    "to": "+33612345678",
    "body": "Hello dans 30 minutes",
    "mediaUrl": null,
    "status": "queued",
    "error": null,
    "providerMessageId": null,
    "warnings": [
      "This instance is still in the warmup phase."
    ],
    "safety": {
      "decision": "warn",
      "riskLevel": "medium",
      "state": "warming",
      "score": 56
    },
    "createdAt": "2026-04-02T07:30:00.000Z",
    "updatedAt": "2026-04-02T07:30:00.000Z"
  }
}
```

<Note>
  Les warnings safety sont informatifs. En V1, ils ne bloquent pas les messages planifiés.
</Note>

## Common errors

| HTTP  | Code                              | When                                     |
| ----- | --------------------------------- | ---------------------------------------- |
| `400` | `VALIDATION_ERROR`                | Invalid body                             |
| `400` | `TEMPLATE_INVALID`                | Template invalid                         |
| `404` | `NOT_FOUND`                       | Instance, contact, or template not found |
| `429` | `MONTHLY_OUTBOUND_QUOTA_EXCEEDED` | Quota already exhausted                  |
