//native
type Gorgias = {
username: string;
apiKey: string;
domain: string;
};
/**
* Create a job
* 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.
*/
export async function main(
auth: Gorgias,
body: {
meta?: {};
params: {
updates?: {};
apply_and_close?: false | true;
view_id?: number;
url?: string;
macro_id?: number;
view?: {};
end_datetime?: string;
start_datetime?: string;
ticket_ids?: number[];
};
scheduled_datetime?: string;
type:
| "applyMacro"
| "deleteTicket"
| "exportTicket"
| "importMacro"
| "exportMacro"
| "updateTicket";
},
) {
const url = new URL(`https://${auth.domain}.gorgias.com/api/jobs`);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 235 days ago