Edits history of script submission #22797 for ' Delete Media (whatsapp_business)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Delete Media
     * Delete an uploaded media item by its media ID.
     */
    export async function main(auth: RT.WhatsappBusiness, media_id: string) {
      const apiVersion = auth.api_version || "v25.0"
      const url = new URL(`https://graph.facebook.com/${apiVersion}/${media_id}`)
      url.searchParams.append("phone_number_id", auth.phone_number_id)
    
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          Accept: "application/json",
        },
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago