0

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

37
  const response = await fetch(url, {
38
    method: "PUT",
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