MediaResource
Defined in: src/resources/media.ts:60
Media API exposed as client.media.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new MediaResource(
request,getDefaultPhoneNumberId):MediaResource
Defined in: src/resources/media.ts:64
Parameters
Section titled “Parameters”request
Section titled “request”RequestFn
getDefaultPhoneNumberId
Section titled “getDefaultPhoneNumberId”PhoneNumberIdAccessor
Returns
Section titled “Returns”MediaResource
Methods
Section titled “Methods”delete()
Section titled “delete()”delete(
mediaId,options?):Promise<DeleteMediaResponse>
Defined in: src/resources/media.ts:153
Deletes a media object by id.
Parameters
Section titled “Parameters”mediaId
Section titled “mediaId”string
options?
Section titled “options?”Returns
Section titled “Returns”Promise<DeleteMediaResponse>
download()
Section titled “download()”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.
Parameters
Section titled “Parameters”mediaId
Section titled “mediaId”string
options?
Section titled “options?”Returns
Section titled “Returns”Promise<DownloadMediaResult>
downloadByUrl()
Section titled “downloadByUrl()”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.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<Uint8Array<ArrayBufferLike>>
getUrl()
Section titled “getUrl()”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).
Parameters
Section titled “Parameters”mediaId
Section titled “mediaId”string
options?
Section titled “options?”Returns
Section titled “Returns”Promise<MediaInfo>
upload()
Section titled “upload()”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.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”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.