//native
type Gorgias = {
username: string;
apiKey: string;
domain: string;
};
/**
* Update a job
*
*/
export async function main(
auth: Gorgias,
id: string,
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;
status?:
| "cancel_requested"
| "canceled"
| "done"
| "errored"
| "fatal_errored"
| "pending"
| "running"
| "scheduled";
},
) {
const url = new URL(`https://${auth.domain}.gorgias.com/api/jobs/${id}/`);
const response = await fetch(url, {
method: "PUT",
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