0

Create an integration

by
Published Oct 17, 2025
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 an integration
9
 *
10
 */
11
export async function main(
12
  auth: Gorgias,
13
  body: {
14
    deactivated_datetime?: string;
15
    description?: string;
16
    http?: {
17
      form?: {};
18
      headers?: {};
19
      method?: "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "PATCH";
20
      request_content_type?:
21
        | "application/json"
22
        | "application/x-www-form-urlencoded";
23
      response_content_type?: "application/json";
24
      triggers?: {
25
        "ticket-updated"?: false | true;
26
        "ticket-created"?: false | true;
27
        "ticket-message-created"?: false | true;
28
      };
29
      url: string;
30
    };
31
    name: string;
32
    type: "http";
33
  },
34
) {
35
  const url = new URL(`https://${auth.domain}.gorgias.com/api/integrations`);
36

37
  const response = await fetch(url, {
38
    method: "POST",
39
    headers: {
40
      "Content-Type": "application/json",
41
      Authorization: "Basic " + btoa(`${auth.username}:${auth.apiKey}`),
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51