0

Update a job

by
Published Oct 17, 2025
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
 * Update a job
9
 *
10
 */
11
export async function main(
12
  auth: Gorgias,
13
  id: string,
14
  body: {
15
    meta?: {};
16
    params?: {
17
      updates?: {};
18
      apply_and_close?: false | true;
19
      view_id?: number;
20
      url?: string;
21
      macro_id?: number;
22
      view?: {};
23
      end_datetime?: string;
24
      start_datetime?: string;
25
      ticket_ids?: number[];
26
    };
27
    scheduled_datetime?: string;
28
    status?:
29
      | "cancel_requested"
30
      | "canceled"
31
      | "done"
32
      | "errored"
33
      | "fatal_errored"
34
      | "pending"
35
      | "running"
36
      | "scheduled";
37
  },
38
) {
39
  const url = new URL(`https://${auth.domain}.gorgias.com/api/jobs/${id}/`);
40

41
  const response = await fetch(url, {
42
    method: "PUT",
43
    headers: {
44
      "Content-Type": "application/json",
45
      Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
46
    },
47
    body: JSON.stringify(body),
48
  });
49
  if (!response.ok) {
50
    const text = await response.text();
51
    throw new Error(`${response.status} ${text}`);
52
  }
53
  return await response.json();
54
}
55