0

Update Form

by
Published Oct 17, 2025

Updates requested form.

Script kustomer Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Kustomer = {
3
  apiKey: string;
4
};
5
/**
6
 * Update Form
7
 * Updates requested form.
8
 */
9
export async function main(
10
  auth: Kustomer,
11
  id: string,
12
  body: {
13
    name?: string;
14
    slug?: string;
15
    body?: string;
16
    published?: false | true;
17
    snippets?: string[];
18
    layout?: unknown[];
19
    components?: {};
20
    layoutV2?: unknown[];
21
    componentsV2?: {};
22
    knowledgeBase?: string;
23
    advanced?: false | true;
24
    recaptcha?: false | true;
25
    klass?: "conversation";
26
    channel?: "email";
27
    deflection?: false | true;
28
    formHookEnabled?: false | true;
29
    replyFrom?: string;
30
  },
31
) {
32
  const url = new URL(`https://api.kustomerapp.com/v1/kb/forms/${id}`);
33

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