//native
type Gorgias = {
username: string;
apiKey: string;
domain: string;
};
/**
* Create a rule
*
*/
export async function main(
auth: Gorgias,
body: {
code: string;
code_ast?: {};
deactivated_datetime?: string;
description?: string;
event_types?:
| "ticket-created"
| "ticket-updated"
| "ticket-message-created"
| "ticket-assigned"
| "ticket-self-unsnoozed";
name: string;
priority?: number;
},
) {
const url = new URL(`https://${auth.domain}.gorgias.com/api/rules`);
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