# Send document

> Send a PDF or another document with a file name and caption over WhatsApp, Instagram or Messenger.

Send a document with `POST /v1/messages` and `type: "document"`. Fields shared by every type (`to`, `reply_to`, `typing`, `delay_ms`, the 24 h window) are in [Common fields](/en/send/text/#common-fields).

  **cURL**

```bash
curl -X POST https://api.messajo.com/v1/messages \
  -H "Authorization: Bearer $MESSAJO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "connection_id": "con_123",
  "to": "5511999990000",
  "type": "document",
  "document": {
    "link": "https://cdn.example.com/invoice-november.pdf",
    "filename": "invoice-november.pdf",
    "caption": "Your November invoice"
  }
}'
```

  **TypeScript**

```ts
import { Messajo } from "@messajo/sdk";

const messajo = new Messajo({ apiKey: process.env.MESSAJO_API_KEY! });

const message = await messajo.messages.send({
  connection_id: "con_123",
  to: "5511999990000",
  type: "document",
  document: {
    link: "https://cdn.example.com/invoice-november.pdf",
    filename: "invoice-november.pdf",
    caption: "Your November invoice"
  },
});
console.log(message.id, message.status);
```

  **n8n**
n8n HTTP Request: POST https://api.messajo.com/v1/messages

```json
{
  "connection_id": "con_123",
  "to": "5511999990000",
  "type": "document",
  "document": {
    "link": "https://cdn.example.com/invoice-november.pdf",
    "filename": "invoice-november.pdf",
    "caption": "Your November invoice"
  }
}
```

The response is `201` with `id` (`msg_…`), `status: "queued"` and `conversation_id`. The final state arrives by webhook.

## Link or upload

Provide **exactly one** of `link` and `media_id`. Sending both, or neither, returns `400 validation_failed` with `exactly one of media_id or link is required`.

- `link`: URL of the document.
- `media_id` (`med_…`): comes from `POST /v1/media`, a `multipart/form-data` request with `file` (and `connection_id`, except with a connection key `mjc_…`). Requires the `send` permission. The type is read from the file bytes, not the extension.

  **cURL**

```bash
curl -X POST https://api.messajo.com/v1/media \
  -H "Authorization: Bearer $MESSAJO_API_KEY" \
  -F connection_id=con_123 \
  -F file=@invoice-november.pdf
```

  **TypeScript**

```ts
import { readFile } from "node:fs/promises";

const media = await messajo.media.upload({
  file: new Blob([await readFile("invoice-november.pdf")]),
  connection_id: "con_123",
});

await messajo.messages.send({
  connection_id: "con_123",
  to: "5511999990000",
  type: "document",
  document: { media_id: media.id, filename: "invoice-november.pdf" },
});
```

The upload returns the media `id` (`med_…`), which you use in `document.media_id`.

## WhatsApp

- `document.caption`: caption of up to 1024 characters.
- `document.filename`: name shown to the contact, up to 240 characters. Always send it, with the extension (`invoice-november.pdf`), so the contact sees a readable name.
- Upload: up to **100 MiB**.

The upload recognises these formats:

| Format | Extensions |
| --- | --- |
| PDF | `.pdf` |
| Legacy Office | `.doc`, `.xls`, `.ppt` |
| Office | `.docx`, `.xlsx`, `.pptx` |
| Plain text | `.txt` |

Office files are identified by their bytes **and** by the extension in the file name. Other formats return `415 media_type_not_supported`.

## Instagram and Messenger

The body is just `link` or `media_id`, with two differences:

- `link` must be `https`.
- There is no `caption` or `filename`. Send the caption as a separate text message.

| Channel | Max size | Formats |
| --- | --- | --- |
| Instagram | 25 MB | `application/pdf` |
| Messenger | 25 MB | `application/pdf` |

## Errors

| Code | Status | When |
| --- | --- | --- |
| `validation_failed` | 400 | `link` and `media_id` together, or neither |
| `media_too_large` | 413 | File above the channel limit |
| `media_type_not_supported` | 415 | Format the channel does not accept |
| `media_error` | 422 | Meta could not process the file |
| `outside_service_window` | 422 | Free-form message outside the 24 h window |
