Edits history of script submission #16244 for ' Delete a ticket (gorgias)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gorgias = {
      username: string;
      apiKey: string;
      domain: string;
    };
    /**
     * Delete a ticket
     *
     */
    export async function main(auth: Gorgias, id: string) {
      const url = new URL(`https://${auth.domain}.gorgias.com/api/tickets/${id}/`);
    
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago