Bulk Mark Tickets as Spam

Accepts a comma-separated list of up to 100 ticket ids. This endpoint returns a `job_status` JSON object and queues a background job to do the work. Use the Show Job Status endpoint to check for the job's completion. Only a certain number of jobs can be queued or running at the same time. See Job limit for more information. #### Allowed For * Agents

Script zendesk Verified

by hugo697 ยท 11/7/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 377 days ago
1
type Zendesk = {
2
  username: string;
3
  password: string;
4
  subdomain: string;
5
};
6
/**
7
 * Bulk Mark Tickets as Spam
8
 * Accepts a comma-separated list of up to 100 ticket ids.
9

10
This endpoint returns a `job_status` JSON object and queues a background job to do the work. Use the Show Job Status endpoint to check for the job's completion. Only a certain number of jobs can be queued or running at the same time. See Job limit for more information.
11

12
#### Allowed For
13

14
* Agents
15
 */
16
export async function main(auth: Zendesk, ids: string | undefined) {
17
  const url = new URL(
18
    `https://${auth.subdomain}.zendesk.com/api/v2/tickets/mark_many_as_spam`
19
  );
20
  for (const [k, v] of [["ids", ids]]) {
21
    if (v !== undefined && v !== "") {
22
      url.searchParams.append(k, v);
23
    }
24
  }
25
  const response = await fetch(url, {
26
    method: "PUT",
27
    headers: {
28
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38