Update an organization webhook

Updates a webhook configured in an organization. When you update a webhook, the `secret` will be overwritten. If you previously had a `secret` set, you must provide the same `secret` or set a new `secret` or the secret will be removed. If you are only updating individual webhook `config` properties, use "Update a webhook configuration for an organization."

Script github Verified

by hugo697 ยท 10/25/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 367 days ago
1
type Github = {
2
  token: string;
3
};
4
/**
5
 * Update an organization webhook
6
 * Updates a webhook configured in an organization. When you update a webhook, the `secret` will be overwritten. If you previously had a `secret` set, you must provide the same `secret` or set a new `secret` or the secret will be removed. If you are only updating individual webhook `config` properties, use "Update a webhook configuration for an organization."
7
 */
8
export async function main(
9
  auth: Github,
10
  org: string,
11
  hook_id: string,
12
  body: {
13
    active?: boolean;
14
    config?: {
15
      content_type?: string;
16
      insecure_ssl?: string | number;
17
      secret?: string;
18
      url: string;
19
      [k: string]: unknown;
20
    };
21
    events?: string[];
22
    name?: string;
23
    [k: string]: unknown;
24
  }
25
) {
26
  const url = new URL(`https://api.github.com/orgs/${org}/hooks/${hook_id}`);
27

28
  const response = await fetch(url, {
29
    method: "PATCH",
30
    headers: {
31
      "Content-Type": "application/json",
32
      Authorization: "Bearer " + auth.token,
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.json();
41
}
42