Skip to content

MediaResource

Defined in: src/resources/media.ts:60

Media API exposed as client.media.

new MediaResource(request, getDefaultPhoneNumberId): MediaResource

Defined in: src/resources/media.ts:64

RequestFn

PhoneNumberIdAccessor

MediaResource

delete(mediaId, options?): Promise<DeleteMediaResponse>

Defined in: src/resources/media.ts:153

Deletes a media object by id.

string

MediaRequestOptions

Promise<DeleteMediaResponse>


download(mediaId, options?): Promise<DownloadMediaResult>

Defined in: src/resources/media.ts:126

Resolves the download URL for a media id and fetches its bytes.

Returns the raw bytes as a Uint8Array alongside the reported MIME type and SHA-256 checksum.

string

MediaRequestOptions

Promise<DownloadMediaResult>


downloadByUrl(url): Promise<Uint8Array<ArrayBufferLike>>

Defined in: src/resources/media.ts:140

Downloads media bytes from an absolute Graph CDN URL (as returned by MediaResource.getUrl). Sends the bearer token and a User-Agent.

string

Promise<Uint8Array<ArrayBufferLike>>


getUrl(mediaId, options?): Promise<MediaInfo>

Defined in: src/resources/media.ts:104

Retrieves metadata for a media id, including a short-lived download url.

The returned url expires quickly and must be fetched with the bearer token (handled by MediaResource.download).

string

MediaRequestOptions

Promise<MediaInfo>


upload(input, options?): Promise<UploadMediaResponse>

Defined in: src/resources/media.ts:77

Uploads a file and returns its reusable media id.

Accepts a Blob/File directly, or { file, filename?, type? } wrapping Blob/Uint8Array/ArrayBuffer bytes. A content type is required: it is taken from a Blob’s type or the explicit type option, otherwise this throws WhatsAppValidationError.

MediaUploadInput

MediaRequestOptions

Promise<UploadMediaResponse>

Independent open-source project. Not affiliated with, endorsed by or sponsored by Meta or WhatsApp. Released under the MIT licence. Source on GitHub.