0

Get multiple webhooks

by
Published Oct 31, 2023

Get the compact representation of all webhooks your app has registered for the authenticated user in the given workspace.

Script asana Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 403 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get multiple webhooks
6
 * Get the compact representation of all webhooks your app has registered for the authenticated user in the given workspace.
7
 */
8
export async function main(
9
  auth: Asana,
10
  opt_pretty: string | undefined,
11
  opt_fields: string | undefined,
12
  limit: string | undefined,
13
  offset: string | undefined,
14
  workspace: string | undefined,
15
  resource: string | undefined
16
) {
17
  const url = new URL(`https://app.asana.com/api/1.0/webhooks`);
18
  for (const [k, v] of [
19
    ["opt_pretty", opt_pretty],
20
    ["opt_fields", opt_fields],
21
    ["limit", limit],
22
    ["offset", offset],
23
    ["workspace", workspace],
24
    ["resource", resource],
25
  ]) {
26
    if (v !== undefined && v !== "") {
27
      url.searchParams.append(k, v);
28
    }
29
  }
30
  const response = await fetch(url, {
31
    method: "GET",
32
    headers: {
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: undefined,
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43