Modify a webhook
One script reply has been approved by the moderators Verified
Created by hugo697 329 days ago
Submitted by hugo697 Bun
Verified 329 days ago
1
//native
2
type Grist = {
3
  apiKey: string;
4
  host: string;
5
};
6
/**
7
 * Modify a webhook
8
 *
9
 */
10
export async function main(
11
  auth: Grist,
12
  docId: string,
13
  webhookId: string,
14
  body: {
15
    name?: string;
16
    memo?: string;
17
    url?: string;
18
    enabled?: false | true;
19
    eventTypes?: string[];
20
    isReadyColumn?: string;
21
    tableId?: string;
22
  },
23
) {
24
  const url = new URL(
25
    `https://${auth.host}/api/docs/${docId}/webhooks/${webhookId}`,
26
  );
27

28
  const response = await fetch(url, {
29
    method: "PATCH",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Bearer " + auth.apiKey,
33
    },
34
    body: JSON.stringify(body),
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.text();
41
}
42