0

Cancel a job

by
Published Oct 17, 2025

Jobs can be canceled at any time but be aware that if a job already started, changes done by this one won't be reverted. For example, if you created a job to close 10k tickets and you cancel it at some point, these closed tickets won't be reopened.

Script gorgias Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Gorgias = {
3
  username: string;
4
  apiKey: string;
5
  domain: string;
6
};
7
/**
8
 * Cancel a job
9
 * Jobs can be canceled at any time but be aware that if a job already started, changes done by this one won't be reverted. For example, if you created a job to close 10k tickets and you cancel it at some point, these closed tickets won't be reopened.
10

11
 */
12
export async function main(auth: Gorgias, id: string) {
13
  const url = new URL(`https://${auth.domain}.gorgias.com/api/jobs/${id}/`);
14

15
  const response = await fetch(url, {
16
    method: "DELETE",
17
    headers: {
18
      Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
19
    },
20
    body: undefined,
21
  });
22
  if (!response.ok) {
23
    const text = await response.text();
24
    throw new Error(`${response.status} ${text}`);
25
  }
26
  return await response.text();
27
}
28