Skip to content
Get started
Esc
Download a file

Media

GET /v1/media/{id}

A file a customer sent, by the media_id from message.received. The response is the file itself, its type in Content-Type. We read the file from the channel while you download it and keep no copy, so the channel decides how long it lasts: until expires_at, 7 days on WhatsApp, and after that the response is 410 media_expired. With a test key it is a sample file.

Path parameters

id string required
The file's media_id from an incoming message, starting with med_.

Errors

CodeHTTPWhat it means
media_not_found404No such file. A key sees only the files of its own workspace and its own mode, live or test. A file uploaded for one channel goes only on that channel, and GET /v1/media/{id} downloads only files customers sent.
media_expired410The channel no longer keeps this file: WhatsApp keeps a file a customer sent for 7 days and an uploaded one for 30. Download a customer's file sooner, and upload yours again.
channel_error422The channel did not take the message. Try again later, and if it still fails, write to us.

Any request can also get the codes on Errors, such as unauthenticated and rate_limited.

Code language
// npm install @airboxhq/api
// AIRBOX_API_KEY=YOUR_API_KEY node download_media.mjs
import { writeFile } from "node:fs/promises";
import { Airbox } from "@airboxhq/api";

const client = new Airbox(process.env.AIRBOX_API_KEY);

const { data, error } = await client.media.download("med_0199c5e2-6a2a-7b41-8e0d-2f1c3a4b5d6f");

if (error) {
  throw new Error(`${error.code}: ${error.message} (${error.requestId})`);
}

await writeFile("voice.ogg", data);
Response 200
Content-Type: audio/ogg
Content-Length: 14695
Content-Disposition: attachment; filename="med_0199c5e2-6a2a-7b41-8e0d-2f1c3a4b5d6f.ogg"
Cache-Control: no-store