Tutorial

Send Invoices and PDFs on WhatsApp with an API

Any statistics or percentages in this article are general industry figures or illustrations, not QuackAPI measurements or promises. Results depend on your audience, consent and sending patterns. QuackAPI connects to WhatsApp as a linked device (an unofficial method), so read our risk and acceptable use policy before sending.

November 12, 20267 min read

Sending a PDF takes one request

Customers open WhatsApp more often than their inbox, so an invoice or receipt sent there gets seen. With QuackAPI you send a document with a single POST to /v1/messages/document. You give it the device, the recipient and a URL where the file can be downloaded, and QuackAPI fetches the file and sends it.

The one thing to get right is the URL. This guide shows how to host the file safely, send it from Node.js and Python, and avoid leaking someone's invoice.

Only message people who have agreed to hear from you. QuackAPI is a linked-device service, not Meta's official Cloud API, so WhatsApp can restrict a number it considers abusive. Read the acceptable use policy before you automate anything.

The request

Send a JSON body with deviceId (the numeric id of your connected device), to (the recipient number in international format, digits only), document (a URL to the file) and an optional filename, which is what the recipient sees. Authenticate with your API key in the x-api-key header.

bash
curl -X POST https://quackapi.com/v1/messages/document \
  -H "Content-Type: application/json" \
  -H "x-api-key: $QUACKAPI_KEY" \
  -d '{
    "deviceId": 1,
    "to": "923001234567",
    "document": "https://files.example.com/invoices/1042.pdf?sig=abc123",
    "filename": "invoice-1042.pdf"
  }'

Hosting the PDF: the part people get wrong

QuackAPI has to download the file from the URL you provide, so the URL must be reachable from the internet without a login. That does not mean it should be permanent or guessable. An invoice contains a name, an address and amounts. A link like https://yoursite.com/invoices/1042.pdf is easy to guess by changing the number.

Use a signed, expiring URL instead. Cloud storage such as Amazon S3, Google Cloud Storage and Cloudflare R2 can generate a link that works for a short time, for example ten minutes, and then stops working. Generate the link, send the message straight away, and let it expire.

ApproachSafe for invoices?Notes
Public file with a sequential nameNoAnyone can guess other invoices by changing the number.
Public file with a long random nameBetterHard to guess, but the link works forever once shared.
Signed URL that expires in minutesYesBest option. Generate it right before you send.
Link that needs a loginWill not workQuackAPI cannot log in, so the download fails.

Node.js example with an S3 signed URL

This function creates a short-lived download link for a private S3 object and then sends it. The same idea works with any storage provider that can sign URLs.

javascript
const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3");
const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");

const s3 = new S3Client({ region: "eu-west-1" });

async function sendInvoice(order, phone) {
  // 1. a link that works for 10 minutes
  const url = await getSignedUrl(
    s3,
    new GetObjectCommand({ Bucket: "my-private-invoices", Key: "invoices/" + order.id + ".pdf" }),
    { expiresIn: 600 }
  );

  // 2. send the document
  const res = await fetch("https://quackapi.com/v1/messages/document", {
    method: "POST",
    headers: { "Content-Type": "application/json", "x-api-key": process.env.QUACKAPI_KEY },
    body: JSON.stringify({
      deviceId: Number(process.env.QUACKAPI_DEVICE),
      to: phone,
      document: url,
      filename: "invoice-" + order.id + ".pdf",
    }),
  });

  const data = await res.json();
  if (!res.ok) throw new Error(res.status + " " + data.message);
  return data.messageId; // status is "queued"
}

Python example

The same request with the requests library. Here the link comes from your own app, for example a one-time download route.

python
import os
import requests

def send_invoice(phone: str, invoice_url: str, order_id: int) -> int:
    res = requests.post(
        "https://quackapi.com/v1/messages/document",
        headers={"x-api-key": os.environ["QUACKAPI_KEY"]},
        json={
            "deviceId": int(os.environ["QUACKAPI_DEVICE"]),
            "to": phone,
            "document": invoice_url,
            "filename": f"invoice-{order_id}.pdf",
        },
        timeout=30,
    )
    data = res.json()
    if not res.ok:
        raise RuntimeError(f"{res.status_code}: {data.get('message')}")
    return data["messageId"]

Send a short text first

A bare PDF from an unknown number looks suspicious. Send a one-line text before it, such as: Hi Sara, your invoice 1042 from Northwind is attached. Make sure your WhatsApp profile name is your business name. The document endpoint does not take a caption today, so a separate text message is how you add context. Two messages per invoice is fine, but do not add more than you need.

Know that queued is not delivered

A 200 response with status queued means QuackAPI accepted the request. The final result arrives on your webhook as message.sent or message.failed. Save the messageId against the invoice so you can match the result, and alert your team when a document fails, for example when the number is not on WhatsApp. See the webhook reference for the events.

Frequently asked questions

Can I send a PDF file directly instead of a URL?
The document endpoint takes a URL. Upload the file to your own storage, create a link QuackAPI can download, and send that link.
Which file types can I send?
The endpoint is meant for documents such as PDF files. Use the image, video and audio endpoints for those media types. Check the API docs for current details.
Is it safe to put customer invoices on a public URL?
Only with a long random name and a short expiry. Prefer a signed link that expires within minutes.
Will the customer see my number?
Yes. The message comes from the WhatsApp number linked to your device, so use a number your customers recognise.

Where to go next

See WhatsApp appointment reminders for another ready-made use, the API quick start for every field, and the media messages feature page for images, video and audio.

Ready to get started?

Send WhatsApp Messages via API — Free

No Meta Business verification. No credit card. Connect your WhatsApp in under 2 minutes and start sending messages through the REST API.

Related Articles