Edits history of script submission #23836 for ' Get Dynamic Content Item (zendesk)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Dynamic Content Item
     * Retrieve a dynamic content item and its variants (one per locale).
     */
    export async function main(auth: RT.Zendesk, item_id: number) {
      const response = await fetch(
        `https://${auth.subdomain}.zendesk.com/api/v2/dynamic_content/items/${item_id}`,
        {
          headers: {
            Authorization: auth.token
              ? `Bearer ${auth.token}`
              : `Basic ${btoa(`${auth.username}:${auth.password}`)}`,
            Accept: "application/json",
          },
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 2 hours ago