Send a PDF or document on WhatsApp via API

Send a document through the CRPRO Hub by link or media id: the filename field, 100 MB limit, supported file types and why a send can fail later.

Documents are how invoices, statements, tickets and contracts reach a customer on WhatsApp. The payload is close to the image one, with one extra field that matters more than it looks: filename. This tutorial sends a PDF through the CRPRO Hub both by link and by uploaded media id, lists the file types Meta supports, and covers the failure modes specific to documents.

What does a document message look like?

Short answer: type is document, and the document object carries either id or link, plus an optional caption and an optional filename.

The Hub's schema defines exactly four fields inside document: id, link, caption (up to 1,024 characters) and filename (1 to 240 characters). Exactly one of id and link must be present, and a link must use HTTPS. As with every media message, the request returns 202 as soon as the message is accepted, and the file is fetched or resolved afterwards.

curl -X POST https://crprohub.com/api/v1/channels/CHANNEL_UUID/messages \ -H "Authorization: Bearer hub_pk_EXAMPLE_NOT_REAL" \ -H "Idempotency-Key: invoice-1042-pdf" \ -H "Content-Type: application/json" \ -d '{ "to": "5521999999999", "type": "document", "document": { "link": "https://files.example.com/invoices/1042.pdf", "filename": "invoice-1042.pdf", "caption": "Invoice 1042, due on the 10th." } }'

Why does the filename field matter?

Short answer: it is the name the customer sees and the extension WhatsApp uses to pick a file icon. Without it, the client falls back to whatever it can derive from the URL or the upload.

Meta's document reference describes filename as the document name including its extension, and notes that the WhatsApp client uses the extension to choose the icon. A signed storage URL often ends in an opaque token and a query string, which makes a poor name for the customer to see and to save. Setting filename explicitly gives a readable title such as invoice-1042.pdf, and it works the same whether the file came in by link or by media id. Keep the extension consistent with the real content: a PDF named report.docx confuses the client and the person reading it.

How is a document sent by uploaded media id?

Short answer: upload the file as multipart/form-data to the channel's media endpoint, read media_id from the response, then reference it in document.id.

import os, requests BASE = "https://crprohub.com/api/v1/channels/" + os.environ["CHANNEL_ID"] HEADERS = {"Authorization": "Bearer " + os.environ["CRPRO_API_KEY"]} with open("invoice-1042.pdf", "rb") as f: up = requests.post(BASE + "/media", headers=HEADERS, files={"file": ("invoice-1042.pdf", f, "application/pdf")}, timeout=30) up.raise_for_status() media_id = up.json()["data"]["media_id"] send = requests.post( BASE + "/messages", headers={**HEADERS, "Idempotency-Key": "invoice-1042-pdf"}, json={"to": "5521999999999", "type": "document", "document": {"id": media_id, "filename": "invoice-1042.pdf", "caption": "Invoice 1042, due on the 10th."}}, timeout=15, ) send.raise_for_status() print(send.json()["data"]["message_id"])

The upload goes through the Hub host, so the Hub's reference notes that very large files may hit a smaller request size limit than Meta accepts directly. For files near the top of the range, hosting the document behind HTTPS and sending link is the safer route. Uploaded ids are short-lived, so upload at the time of sending rather than storing the id.

Which document types and sizes are supported?

Short answer: up to 100 MB, and officially TXT, XLS, XLSX, DOC, DOCX, PPT, PPTX and PDF. Other types can be sent but may not display as expected.

TypeExtensionMIME type
Plain text.txttext/plain
Excel.xls, .xlsxapplication/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
Word.doc, .docxapplication/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document
PowerPoint.ppt, .pptxapplication/vnd.ms-powerpoint, application/vnd.openxmlformats-officedocument.presentationml.presentation
PDF.pdfapplication/pdf

The 100 MB ceiling is the same figure the Hub lists in its limits table. In practice, a document that large is a poor experience on a mobile connection, so generate compact PDFs for transactional use. Compressing a scanned invoice before sending it avoids both slow downloads and storage surprises on the customer's side.

Can a document start a conversation?

Short answer: not as a free-form message. Outside the 24-hour service window the first message must be a template, and a template can carry a document in its header.

The Hub's template schema accepts a document parameter inside a header component, so the usual pattern for proactive delivery is an approved template whose header holds the file. Inside the window, after the customer has written, the plain document message shown above is enough. Choosing between them is the same check as for text: look at when the customer last wrote. The quickstart covers the authenticated request used throughout this tutorial.

How should filenames and idempotency keys be chosen?

Short answer: build the filename from stable business data the customer recognises, and build the Idempotency-Key from the event that produces the send.

A filename such as invoice-1042.pdf tells the customer what they are holding and keeps their downloads folder tidy; a name containing a timestamp or a random token does neither. The key plays a different role. For a document that goes out once per invoice, use something like invoice-1042-pdf, so that a retried job cannot deliver the same invoice twice. If the invoice is regenerated and genuinely needs to be sent again, include a version in the key, for example invoice-1042-v2-pdf, so the Hub treats it as a new message. Both strings stay below the Hub's limits of 240 characters for the filename and 255 for the key.

What goes wrong with document sends?

Short answer: the usual causes are a link Meta cannot fetch, a file over the size limit, a wrong filename extension and a send outside the window. All of them surface as failed statuses, not as errors on the POST.

  • Link problems: expired signed URLs, redirects to a login page and private buckets all produce a failed status. Use URLs that stay valid for at least a few minutes after the send.
  • Wrong content: a server that returns an HTML error page with a 200 status is accepted as a link but is not a document.
  • Window problems: the document is refused after acceptance because the customer last wrote more than 24 hours ago.
  • Retry mistakes: reusing the Idempotency-Key replays the original response and sends nothing. A deliberate resend needs a new key.

Subscribe an endpoint to message.status, as described in the webhooks reference, and log the error code next to the message_id you saved when sending.

How can document generation be made reliable?

Short answer: generate, validate and store the file before sending, so the send step only references something that is known to be good.

Many document failures begin before the message is sent: a PDF job that wrote an empty file, a template that rendered a blank page or a storage upload that finished after the send call. Separate the stages. Produce the file, check that its size is greater than zero and its type is what you expect, store it, and only then enqueue the send with a reference to the stored object. This ordering also gives you a place to apply virus scanning or watermarking, and a copy of exactly what the customer received.

  • Check the byte size and the MIME type of the generated file.
  • Wait for the storage upload to complete before building the message.
  • Keep the stored copy for as long as your retention policy requires.
  • Send the message through a queue so a failed attempt can be retried without regenerating the file.
  • Record the filename and the message_id together for support lookups.

Frequently asked questions

Is filename required for documents?

No. The Hub schema makes it optional, up to 240 characters. Setting it is still recommended, because it controls the name and icon the customer sees.

Can a document carry a caption?

Yes. The caption is optional and limited to 1,024 characters. It appears under the document in the chat.

Should documents be sent by id or by link?

Meta recommends the uploaded media id for performance. For very large files, the Hub's reference suggests an HTTPS link, because uploads pass through the Hub host and may face a smaller size limit.

Are zip files or images-as-documents allowed?

Meta lists TXT, XLS, XLSX, DOC, DOCX, PPT, PPTX and PDF as supported. Other file types can be sent but are not officially supported and may not display correctly.

Fontes

Documentação oficial da Meta, conferida em 31 de outubro de 2026.