Edits history of script submission #23845 for ' Get Side Conversation (zendesk)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Get Side Conversation
     * Retrieve one of a ticket's side conversations, optionally with its events (the messages sent and received).
     */
    export async function main(
      auth: RT.Zendesk,
      ticket_id: number,
      side_conversation_id: string,
      include_events: boolean
    ) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/tickets/${ticket_id}/side_conversations/${side_conversation_id}`
      )
      if (include_events) {
        url.searchParams.append("include", "events")
      }
    
      const response = await fetch(url, {
        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