0
Get tags in a workspace
One script reply has been approved by the moderators Verified

Returns the compact tag records for some filtered set of tags. Use one or more of the parameters provided to filter the tags returned.

Created by hugo697 418 days ago Viewed 9154 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 418 days ago
1
type Asana = {
2
  token: string;
3
};
4
/**
5
 * Get tags in a workspace
6
 * Returns the compact tag records for some filtered set of tags. Use one or more of the parameters provided to filter the tags returned.
7
 */
8
export async function main(
9
  auth: Asana,
10
  workspace_gid: string,
11
  opt_pretty: string | undefined,
12
  opt_fields: string | undefined,
13
  limit: string | undefined,
14
  offset: string | undefined
15
) {
16
  const url = new URL(
17
    `https://app.asana.com/api/1.0/workspaces/${workspace_gid}/tags`
18
  );
19
  for (const [k, v] of [
20
    ["opt_pretty", opt_pretty],
21
    ["opt_fields", opt_fields],
22
    ["limit", limit],
23
    ["offset", offset],
24
  ]) {
25
    if (v !== undefined && v !== "") {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
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