Sign inGet Started

Upload a WhatsApp file

POST
/v1/whatsapp/files
import { readFile } from "node:fs/promises";

const file = await bird.whatsapp.files.create({
  from: "+13124495648",
  file: new Blob([await readFile("invoice-4821.pdf")]),
  name: "invoice-4821.pdf",
});
// Send it from the same number as document.file_id.
console.log(file.id, file.mime_type, file.expires_at);
Respuesta201
{
  "id": "waf_01krdgeqcxet5s7t44vh8rt9mg",
  "from": "+13124495648",
  "name": "receipt.pdf",
  "mime_type": "application/pdf",
  "size": 48213,
  "created_at": "2026-12-03T12:00:00Z",
  "expires_at": "2027-01-02T12:00:00Z"
}

Stores a file for the workspace's WhatsApp messages, hands it to WhatsApp for one of the workspace's numbers, and returns it. Send the file as multipart/form-data with from, the connected E.164 number the file is uploaded with, before file, at most 100 MB; a larger one returns 413. A missing, unknown or not yet connected from returns 422. The name is name, else the uploaded filename; a request that yields none returns 422. The media type is mime_type, else the type we detect from the contents; send mime_type for a type detection cannot tell apart, such as an Office document or AAC, AMR, M4A or 3GPP media. WhatsApp carries JPEG and PNG images; WebP stickers; MP4 and 3GPP video; AAC, AMR, MP3, M4A and Ogg audio; and PDF, plain text and Office documents. Any other type is refused with 422, as is a file whose contents do not match its media type, such as a JPEG declared as a PDF. A mime_type of application/octet-stream is read as none given. A JPEG or PNG image is stored re-encoded from its pixels, upright and without its metadata, as the asset library stores images, so it must decode, fit 5 MB and have at most 25 megapixels and 20,000 pixels per side; every other file is stored as sent.

The file is uploaded to WhatsApp before the request answers, with the number's own credential. A file WhatsApp refuses returns 422 whose vendor_code is WhatsApp's own error code; no file is created, so there is no id to read or send, and the private copy Bird staged for the hand-over, which nothing can read, is deleted with the 30-day expiry. A WhatsApp outage or rate limit returns 503, which can be retried with the same Idempotency-Key. A number whose credential WhatsApp no longer accepts returns the same 422 as a from that is not connected, with WhatsApp's error code as vendor_code; the number may still read connected: disconnect it and connect it again through WhatsApp Embedded Signup, then upload again.

Send the file by passing its id as file_id on a free-form media send, or on a template's media header parameter (header_file_id in template.parameters), from the same from; a send from another number is refused with 422. The file is kept for 30 days after it is uploaded and then returns 404; a send within 24 hours of that time is refused with 422. WhatsApp keeps its copy for the same 30 days; should it drop the copy earlier, a send of the file fails after acceptance with a media failure (a failed message, media_rejected when WhatsApp reports a media error) and the file must be uploaded again. Media you reuse and are happy to host publicly, such as a logo, can live in the asset library (/v1/assets), whose public URL a message's media takes as url; asset URLs stay reachable after the asset is deleted, and the library takes smaller files and fewer types than WhatsApp. Anything else, such as a private document or a video, is uploaded here or sent from a URL you host.

Each request stores a new file; retry with the same Idempotency-Key to receive the first result without uploading the file to WhatsApp again.

Carga de respuesta

id
string
obligatorio

ID of the stored file, which a free-form media send or a template's media header accepts as file_id.

from
string
obligatorio

The E.164 number the file was uploaded to WhatsApp with; only a message from this number can send it.

name
string
obligatorio

Display filename.

mime_type
string
obligatorio

Media type of the file.

size
integer
obligatorio

File size in bytes.

created_at
string
obligatorio

When the file was stored.

expires_at
string
obligatorio

When the file is removed, 30 days after it was stored. A send within 24 hours of this time is refused.