Edits history of script submission #4028 for ' List Activities (zendesk)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Zendesk = {
      username: string;
      password: string;
      subdomain: string;
    };
    /**
     * List Activities
     * Lists ticket activities in the last 30 days affecting the agent making the request.
    Also sideloads the following arrays of user records:
    
    - actors - All actors involved in the listed activities
    - users - All users involved in the listed activities
    
    #### Pagination
    
    - Cursor pagination (recommended)
    - Offset pagination
    
    See Pagination.
    
    Returns a maximum of 100 records per page.
    
    #### Allowed For
    
    * Agents
    
     */
    export async function main(auth: Zendesk, since: string | undefined) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/activities`
      );
      for (const [k, v] of [["since", since]]) {
        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 Activities
     * Lists ticket activities in the last 30 days affecting the agent making the request.
    Also sideloads the following arrays of user records:
    
    - actors - All actors involved in the listed activities
    - users - All users involved in the listed activities
    
    #### Pagination
    
    - Cursor pagination (recommended)
    - Offset pagination
    
    See Pagination.
    
    Returns a maximum of 100 records per page.
    
    #### Allowed For
    
    * Agents
    
     */
    export async function main(auth: Zendesk, since: string | undefined) {
      const url = new URL(
        `https://${auth.subdomain}.zendesk.com/api/v2/activities`
      );
      for (const [k, v] of [["since", since]]) {
        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