Media

Every request sends x-api-key. New here? Start with the quickstart, or read API keys.

OperationSDK callEndpoint
Upload a filemedia.uploadPOST /v1/media/

Upload a file

Upload a file and receive a med_ id to send with. Send the file as the body of a multipart/form-data request; no other fields are needed. The file is stored and registered with WhatsApp in one call, so the returned id is immediately usable. Idempotency-Key is honoured: the file itself is part of the fingerprint, so a retry replays the first result rather than storing a second copy.

const bytes = new Uint8Array();
const file = new Blob([bytes], { type: "application/pdf" });
await msg.media.upload(file, "invoice.pdf");

Body

multipart/form-data with the file in a file part.

Response 201

Example response
{
  "id": "med_7c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f",
  "filename": "invoice.pdf",
  "mimeType": "application/pdf"
}
FieldTypeDescription
idstringPass this to POST /v1/messages as mediaId.
filenamestringThe name the file was uploaded under.
mimeTypestringThe type we normalised to, which may differ from the one you declared.
sizeBytesintegerSize of the stored file.
createdAtstring (ISO 8601)When the file was uploaded.

Errors

Returns 400, 401, 403, 429, 502, 503. Every one carries the standard envelope — branch on code, not the status. See Errors.