//native
type Gorgias = {
username: string;
apiKey: string;
domain: string;
};
/**
* Create an integration
*
*/
export async function main(
auth: Gorgias,
body: {
deactivated_datetime?: string;
description?: string;
http?: {
form?: {};
headers?: {};
method?: "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "PATCH";
request_content_type?:
| "application/json"
| "application/x-www-form-urlencoded";
response_content_type?: "application/json";
triggers?: {
"ticket-updated"?: false | true;
"ticket-created"?: false | true;
"ticket-message-created"?: false | true;
};
url: string;
};
name: string;
type: "http";
},
) {
const url = new URL(`https://${auth.domain}.gorgias.com/api/integrations`);
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