Edits history of script submission #16288 for ' Update a macro (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 macro
     *
     */
    export async function main(
      auth: Gorgias,
      id: string,
      body: {
        external_id?: string;
        name?: string;
        intent?:
          | "discount/request"
          | "exchange/request"
          | "exchange/status"
          | "feedback"
          | "order/damaged"
          | "order/cancel"
          | "order/change"
          | "order/wrong"
          | "other/no_reply"
          | "other/question"
          | "other/thanks"
          | "product/recommendation"
          | "product/question"
          | "refund/request"
          | "refund/status"
          | "return/request"
          | "return/status"
          | "shipping/change"
          | "shipping/delivery-issue"
          | "shipping/policy"
          | "shipping/status"
          | "stock/request"
          | "subscription/cancel"
          | "subscription/change";
        language?: string;
        actions?: {
          description?: string;
          arguments: {};
          type?: "system" | "user";
          name: string;
          title: string;
        }[];
      },
    ) {
      const url = new URL(`https://${auth.domain}.gorgias.com/api/macros/${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