Edits history of script submission #16234 for ' Create 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;
    };
    /**
     * Create a ticket
     *
     */
    export async function main(
      auth: Gorgias,
      body: {
        assignee_team?: { id?: number };
        assignee_user?: { id?: number };
        channel?:
          | "aircall"
          | "api"
          | "chat"
          | "email"
          | "facebook"
          | "facebook-mention"
          | "facebook-messenger"
          | "facebook-recommendations"
          | "help-center"
          | "instagram-ad-comment"
          | "instagram-comment"
          | "instagram-mention"
          | "instagram-direct-message"
          | "internal-note"
          | "phone"
          | "sms"
          | "twitter"
          | "twitter-direct-message"
          | "yotpo-review";
        closed_datetime?: string;
        created_datetime?: string;
        customer?: { id?: number; email?: string };
        external_id?: string;
        from_agent?: false | true;
        language?: string;
        last_message_datetime?: string;
        last_received_message_datetime?: string;
        messages: {
          attachments?: {
            content_type: string;
            extra?: {};
            size: number;
            name: string;
            url: string;
            public?: false | true;
          }[];
          body_html?: string;
          body_text?: string;
          channel:
            | "aircall"
            | "api"
            | "chat"
            | "email"
            | "facebook"
            | "facebook-mention"
            | "facebook-messenger"
            | "facebook-recommendations"
            | "help-center"
            | "instagram-ad-comment"
            | "instagram-comment"
            | "instagram-mention"
            | "instagram-direct-message"
            | "internal-note"
            | "phone"
            | "sms"
            | "twitter"
            | "twitter-direct-message"
            | "yotpo-review";
          created_datetime?: string;
          external_id?: string;
          failed_datetime?: string;
          from_agent: false | true;
          integration_id?: number;
          last_sending_error?: {};
          message_id?: string;
          receiver?: { id?: number; email?: string };
          rule_id?: number;
          sender?: { id?: number; email?: string };
          sent_datetime?: string;
          source?: {
            from?: { name?: string; address?: string };
            bcc?: { name?: string; address?: string }[];
            type?: string;
            to?: { name?: string; address?: string }[];
            cc?: { name?: string; address?: string }[];
          };
          stripped_html?: string;
          stripped_text?: string;
          subject?: string;
          via:
            | "aircall"
            | "api"
            | "chat"
            | "email"
            | "facebook"
            | "facebook-mention"
            | "facebook-messenger"
            | "facebook-recommendations"
            | "help-center"
            | "instagram-ad-comment"
            | "instagram-comment"
            | "instagram-mention"
            | "instagram-direct-message"
            | "internal-note"
            | "phone"
            | "sms"
            | "twitter"
            | "twitter-direct-message"
            | "yotpo-review"
            | "twilio"
            | "zendesk"
            | "form"
            | "self_service"
            | "yotpo"
            | "instagram"
            | "shopify"
            | "gorgias_chat"
            | "rule"
            | "helpdesk";
        }[];
        meta?: {};
        opened_datetime?: string;
        snooze_datetime?: string;
        spam?: false | true;
        status?: "open" | "closed";
        subject?: string;
        tags?: { name?: string }[];
        trashed_datetime?: string;
        updated_datetime?: string;
        via?:
          | "aircall"
          | "api"
          | "chat"
          | "email"
          | "facebook"
          | "facebook-mention"
          | "facebook-messenger"
          | "facebook-recommendations"
          | "help-center"
          | "instagram-ad-comment"
          | "instagram-comment"
          | "instagram-mention"
          | "instagram-direct-message"
          | "internal-note"
          | "phone"
          | "sms"
          | "twitter"
          | "twitter-direct-message"
          | "yotpo-review"
          | "twilio"
          | "zendesk"
          | "form"
          | "self_service"
          | "yotpo"
          | "instagram"
          | "shopify"
          | "gorgias_chat"
          | "rule"
          | "helpdesk";
      },
    ) {
      const url = new URL(`https://${auth.domain}.gorgias.com/api/tickets`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago