Send messages
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.
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" }}'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 HTTP Request node settings
- Method:
POST - URL:
https://api.messajo.com/v1/messages - Authentication: Generic Credential Type, then Header Auth. Name:
Authorization; Value:Bearer mj_... - Headers: turn on Send Headers and add
Idempotency-Key(a unique value per item) - Body: turn on Send Body; Body Content Type: JSON; Specify Body: Using 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" }}Replace mj_... with your API key.
The response is 201 with id (msg_…), status: "queued" and conversation_id. The final state arrives by webhook.
Link or upload
Section titled “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 fromPOST /v1/media, amultipart/form-datarequest withfile(andconnection_id, except with a connection keymjc_…). Requires thesendpermission. The type is read from the file bytes, not the extension.
curl -X POST https://api.messajo.com/v1/media \ -H "Authorization: Bearer $MESSAJO_API_KEY" \ -F connection_id=con_123 \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.
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 |
|
| 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
Section titled “Instagram and Messenger”The body is just link or media_id, with two differences:
linkmust behttps.- There is no
captionorfilename. Send the caption as a separate text message.
| Channel | Max size | Formats |
|---|---|---|
| 25 MB | application/pdf |
|
| Messenger | 25 MB | application/pdf |
Errors
Section titled “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 |