0

List Suspended Tickets

by
Published Nov 7, 2023

#### Pagination * Cursor pagination See Pagination. #### Allowed For * Admins and [agents in custom roles with permission](https://support.zendesk.com/hc/en-us/articles/4408882153882#topic_cxn_hig_bd) to manage suspended tickets on Enterprise plans * Unrestricted agents on all other plans #### Sorting You can sort the tickets with the `sort_by` and `sort_order` query string parameters.

Script zendesk
  • Submitted by hugo697 Typescript (fetch-only)
    Created 536 days ago
    1
    type Zendesk = {
    2
      username: string;
    3
      password: string;
    4
      subdomain: string;
    5
    };
    6
    /**
    7
     * List Suspended Tickets
    8
     * #### Pagination
    9
    
    
    10
    * Cursor pagination
    11
    
    
    12
    See Pagination.
    13
    
    
    14
    #### Allowed For
    15
    
    
    16
    * Admins and [agents in custom roles with permission](https://support.zendesk.com/hc/en-us/articles/4408882153882#topic_cxn_hig_bd) to manage suspended tickets on Enterprise plans
    17
    * Unrestricted agents on all other plans
    18
    
    
    19
    #### Sorting
    20
    
    
    21
    You can sort the tickets with the `sort_by` and `sort_order` query string parameters.
    22
    
    
    23
     */
    24
    export async function main(
    25
      auth: Zendesk,
    26
      sort_by: string | undefined,
    27
      sort_order: string | undefined
    28
    ) {
    29
      const url = new URL(
    30
        `https://${auth.subdomain}.zendesk.com/api/v2/suspended_tickets`
    31
      );
    32
      for (const [k, v] of [
    33
        ["sort_by", sort_by],
    34
        ["sort_order", sort_order],
    35
      ]) {
    36
        if (v !== undefined && v !== "") {
    37
          url.searchParams.append(k, v);
    38
        }
    39
      }
    40
      const response = await fetch(url, {
    41
        method: "GET",
    42
        headers: {
    43
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
    44
        },
    45
        body: undefined,
    46
      });
    47
      if (!response.ok) {
    48
        const text = await response.text();
    49
        throw new Error(`${response.status} ${text}`);
    50
      }
    51
      return await response.json();
    52
    }
    53