0

Delete Media

by
Published today

Delete an uploaded media item by its media ID.

Script whatsapp_business Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 5 hours ago
1
//native
2

3
/**
4
 * Delete Media
5
 * Delete an uploaded media item by its media ID.
6
 */
7
export async function main(auth: RT.WhatsappBusiness, media_id: string) {
8
  const apiVersion = auth.api_version || "v25.0"
9
  const url = new URL(`https://graph.facebook.com/${apiVersion}/${media_id}`)
10
  url.searchParams.append("phone_number_id", auth.phone_number_id)
11

12
  const response = await fetch(url, {
13
    method: "DELETE",
14
    headers: {
15
      Authorization: `Bearer ${auth.token}`,
16
      Accept: "application/json",
17
    },
18
  })
19

20
  if (!response.ok) {
21
    throw new Error(`${response.status} ${await response.text()}`)
22
  }
23

24
  return await response.json()
25
}
26