Edits history of script submission #16295 for ' Update a view (gorgias)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gorgias = {
      username: string;
      apiKey: string;
      domain: string;
    };
    /**
     * Update a view
     *
     */
    export async function main(
      auth: Gorgias,
      id: string,
      body: {
        category?: string;
        deactivated_datetime?: string;
        decoration?: { emoji?: string };
        display_order?: number;
        fields?:
          | "details"
          | "tags"
          | "customer"
          | "last_message"
          | "name"
          | "email"
          | "created"
          | "updated"
          | "assignee"
          | "assignee_team"
          | "channel"
          | "closed"
          | "language"
          | "last_received_message"
          | "integrations"
          | "snooze"
          | "status"
          | "subject"[];
        filters?: string;
        filters_ast?: {};
        name?: string;
        order_by?: string;
        order_dir?: "asc" | "desc";
        shared_with_teams?: number[];
        shared_with_users?: number[];
        slug?: string;
        type?: "ticket-list";
        visibility?: "public" | "shared" | "private";
      },
    ) {
      const url = new URL(`https://${auth.domain}.gorgias.com/api/views/${id}/`);
    
      const response = await fetch(url, {
        method: "PUT",
        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