Edits history of script submission #4147 for ' List Ticket Forms (zendesk)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Zendesk = {
      username: string;
      password: string;
      subdomain: string;
    };
    /**
     * List Ticket Forms
     * Returns a list of all ticket forms for your account if accessed as an admin or agent. End users only see ticket forms that have `end_user_visible` set to true.
    
    #### Allowed For
    
    * Anyone
    
     */
    export async function main(
      auth: Zendesk,
      active: string | undefined,
      end_user_visible: string | undefined,
      fallback_to_default: string | undefined,
      associated_to_brand: string | undefined
    ) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/ticket_forms`
      );
      for (const [k, v] of [
        ["active", active],
        ["end_user_visible", end_user_visible],
        ["fallback_to_default", fallback_to_default],
        ["associated_to_brand", associated_to_brand],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 377 days ago

  • nativets
    type Zendesk = {
      username: string;
      password: string;
      subdomain: string;
    };
    /**
     * List Ticket Forms
     * Returns a list of all ticket forms for your account if accessed as an admin or agent. End users only see ticket forms that have `end_user_visible` set to true.
    
    #### Allowed For
    
    * Anyone
    
     */
    export async function main(
      auth: Zendesk,
      active: string | undefined,
      end_user_visible: string | undefined,
      fallback_to_default: string | undefined,
      associated_to_brand: string | undefined
    ) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/ticket_forms`
      );
      for (const [k, v] of [
        ["active", active],
        ["end_user_visible", end_user_visible],
        ["fallback_to_default", fallback_to_default],
        ["associated_to_brand", associated_to_brand],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 923 days ago