0

Create a job

by
Published Oct 17, 2025

Create a job and schedule its execution. Jobs are processed asynchronously, meaning that once a job is created, it will run in background on Gorgias's servers. According to the type and size of the task, a job can take a few minutes or several hours to be executed. You can use our API to check the status of the job.

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
 * Create a job
9
 * Create a job and schedule its execution. Jobs are processed asynchronously, meaning that once a job is created, it will run in background on Gorgias's servers. According to the type and size of the task, a job can take a few minutes or several hours to be executed. You can use our API to check the status of the job.
10

11
 */
12
export async function main(
13
  auth: Gorgias,
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
    type:
29
      | "applyMacro"
30
      | "deleteTicket"
31
      | "exportTicket"
32
      | "importMacro"
33
      | "exportMacro"
34
      | "updateTicket";
35
  },
36
) {
37
  const url = new URL(`https://${auth.domain}.gorgias.com/api/jobs`);
38

39
  const response = await fetch(url, {
40
    method: "POST",
41
    headers: {
42
      "Content-Type": "application/json",
43
      Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
44
    },
45
    body: JSON.stringify(body),
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