Edits history of script submission #4080 for ' Autocomplete Problems (zendesk)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Zendesk = {
      username: string;
      password: string;
      subdomain: string;
    };
    /**
     * Autocomplete Problems
     * Returns tickets whose type is "problem" and whose subject contains the string specified in the `text` parameter.
    
    You can specify the `text` parameter in the request body rather than the query string. Example:
    
    `{"text": "fire"}`
    
    #### Allowed For
    
    * Agents
     */
    export async function main(
      auth: Zendesk,
      text: string | undefined,
      body: { text?: string; [k: string]: unknown }
    ) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/problems/autocomplete`
      );
      for (const [k, v] of [["text", text]]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        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 377 days ago

  • nativets
    type Zendesk = {
      username: string;
      password: string;
      subdomain: string;
    };
    /**
     * Autocomplete Problems
     * Returns tickets whose type is "problem" and whose subject contains the string specified in the `text` parameter.
    
    You can specify the `text` parameter in the request body rather than the query string. Example:
    
    `{"text": "fire"}`
    
    #### Allowed For
    
    * Agents
     */
    export async function main(
      auth: Zendesk,
      text: string | undefined,
      body: { text?: string; [k: string]: unknown }
    ) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/problems/autocomplete`
      );
      for (const [k, v] of [["text", text]]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        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 923 days ago