Edits history of script submission #16255 for ' List integrations (gorgias)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Gorgias = {
      username: string;
      apiKey: string;
      domain: string;
    };
    /**
     * List integrations
     * List integrations matching the given parameters, paginated.
     */
    export async function main(
      auth: Gorgias,
      cursor: string | undefined,
      _type:
        | "email"
        | "gmail"
        | "outlook"
        | "aircall"
        | "self_service"
        | "smooch_inside"
        | "smooch"
        | "facebook"
        | "gorgias_chat"
        | "phone"
        | "sms"
        | "twitter"
        | "yotpo"
        | "http"
        | "shopify"
        | "recharge"
        | "smile"
        | "magento2"
        | "zendesk"
        | "klaviyo"
        | undefined,
      page: string | undefined,
      per_page: string | undefined,
      limit: string | undefined,
      order_by: "created_datetime:asc" | "created_datetime:desc" | undefined,
    ) {
      const url = new URL(`https://${auth.domain}.gorgias.com/api/integrations`);
      for (const [k, v] of [
        ["cursor", cursor],
        ["type", _type],
        ["page", page],
        ["per_page", per_page],
        ["limit", limit],
        ["order_by", order_by],
      ]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        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.json();
    }
    

    Submitted by hugo697 235 days ago