Edits history of script submission #22811 for ' Update Business Profile (whatsapp_business)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Update Business Profile
     * Update the WhatsApp business profile of the business phone number. Only the provided fields are changed.
     */
    export async function main(
      auth: RT.WhatsappBusiness,
      body: {
        about?: string
        address?: string
        description?: string
        email?: string
        websites?: string[]
        vertical?: string
        profile_picture_handle?: string
      }
    ) {
      const apiVersion = auth.api_version || "v25.0"
      const url = new URL(
        `https://graph.facebook.com/${apiVersion}/${auth.phone_number_id}/whatsapp_business_profile`
      )
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: `Bearer ${auth.token}`,
          "Content-Type": "application/json",
          Accept: "application/json",
        },
        body: JSON.stringify({
          messaging_product: "whatsapp",
          ...body,
        }),
      })
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 5 hours ago