Edits history of script submission #23832 for ' Get Macro (zendesk)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Macro
     * Retrieve a macro, with the actions it applies.
     */
    export async function main(auth: RT.Zendesk, macro_id: number) {
      const response = await fetch(
        `https://${auth.subdomain}.zendesk.com/api/v2/macros/${macro_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