0

Update a widget

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 widget
9
 *
10
 */
11
export async function main(
12
  auth: Gorgias,
13
  id: string,
14
  body: {
15
    context?: "ticket" | "user";
16
    deactivated_datetime?: string;
17
    integration_id?: number;
18
    order?: number;
19
    template?: {};
20
    type?:
21
      | "custom"
22
      | "http"
23
      | "magento2"
24
      | "recharge"
25
      | "shopify"
26
      | "smile"
27
      | "smooch_inside"
28
      | "yotpo"
29
      | "klaviyo"
30
      | "stripe";
31
  },
32
) {
33
  const url = new URL(`https://${auth.domain}.gorgias.com/api/widgets/${id}/`);
34

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