List subscribable webhook types

Returns a paginated list of all valid webhook events for the specified entity.

Script bitbucket Verified

by hugo697 ยท 10/24/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 375 days ago
1
type Bitbucket = {
2
  username: string;
3
  password: string;
4
};
5
/**
6
 * List subscribable webhook types
7
 * Returns a paginated list of all valid webhook events for the
8
specified entity.
9
 */
10
export async function main(
11
  auth: Bitbucket,
12
  subject_type: "repository" | "workspace"
13
) {
14
  const url = new URL(
15
    `https://api.bitbucket.org/2.0/hook_events/${subject_type}`
16
  );
17

18
  const response = await fetch(url, {
19
    method: "GET",
20
    headers: {
21
      Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
22
    },
23
    body: undefined,
24
  });
25
  if (!response.ok) {
26
    const text = await response.text();
27
    throw new Error(`${response.status} ${text}`);
28
  }
29
  return await response.json();
30
}
31