Upload a WhatsApp file
/v1/whatsapp/filesimport { 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);with open("invoice-4821.pdf", "rb") as f:
file = client.whatsapp.files.create(
from_="+13124495648",
file=f,
filename="invoice-4821.pdf",
)
# Send it from the same number as document={"file_id": file.id}.
print(file.id, file.expires_at)invoice, err := os.Open("invoice-4821.pdf")
if err != nil {
log.Fatal(err)
}
defer func() { _ = invoice.Close() }()
file, err := client.Whatsapp.Files.Create(context.Background(), bird.WhatsappFilesCreateParams{
From: "+13124495648",
File: invoice,
Filename: "invoice-4821.pdf",
})
if err != nil {
log.Fatal(err)
}
// Send it from the same number as a document's FileId.
fmt.Println(file.Id, file.MimeType, file.ExpiresAt)$contents = file_get_contents('invoice-4821.pdf');
if ($contents === false) {
exit("Cannot read invoice-4821.pdf\n");
}
$file = $bird->whatsapp->files->create(
from: '+13124495648',
contents: $contents,
filename: 'invoice-4821.pdf',
);
// Send it from the same number as the document's file_id.
echo $file->getId(), ' ', $file->getMimeType(), ' ', $file->getExpiresAt()?->format(DATE_ATOM), "\n";bird whatsapp files upload --from <from> --file ./document.pdfcurl -X POST "https://us1.platform.bird.com/v1/whatsapp/files" \
-H "Authorization: Bearer $TOKEN" \
-H "Idempotency-Key: $IDEMPOTENCY_KEY" \
--form-string 'from=+13124495648' \
--form-string 'name=receipt.pdf' \
--form-string 'mime_type=application/pdf' \
-F 'file=@./file'{
"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.
Payload di risposta
idID of the stored file, which a free-form media send or a template's media header accepts as file_id.
fromThe E.164 number the file was uploaded to WhatsApp with; only a message from this number can send it.
nameDisplay filename.
mime_typeMedia type of the file.
sizeFile size in bytes.
created_atWhen the file was stored.
expires_atWhen the file is removed, 30 days after it was stored. A send within 24 hours of this time is refused.
Risorse correlate
Continua con la documentazione, le guide e gli esempi per questo argomento.