0

List Tags

by
Published Oct 31, 2023

List the tags in a workspace. Pass `next_page.offset` from a response as `offset` to get the next page.

Script asana Verified

The script

Submitted by hugo989 Typescript (fetch-only)
Verified 2 hours ago
1
//native
2

3
export type DynSelect_workspace = string
4

5
// Resolver: the workspaces and organizations the token can access.
6
export async function workspace(auth: RT.Asana) {
7
  const response = await fetch(
8
    "https://app.asana.com/api/1.0/workspaces?limit=100",
9
    {
10
      headers: {
11
        Authorization: `Bearer ${auth.token}`,
12
        Accept: "application/json",
13
      },
14
    }
15
  )
16
  if (!response.ok) {
17
    throw new Error(`${response.status} ${await response.text()}`)
18
  }
19
  const { data } = await response.json()
20
  return data.map((w: { gid: string; name: string }) => ({
21
    value: w.gid,
22
    label: w.name,
23
  }))
24
}
25

26
/**
27
 * List Tags
28
 * List the tags in a workspace. Pass `next_page.offset` from a response as `offset` to get the next page.
29
 */
30
export async function main(
31
  auth: RT.Asana,
32
  workspace: DynSelect_workspace,
33
  opt_fields: string | undefined,
34
  limit: number | undefined,
35
  offset: string | undefined
36
) {
37
  const url = new URL(`https://app.asana.com/api/1.0/tags`)
38
  const params = { workspace, opt_fields, limit: limit ?? 100, offset }
39
  for (const [key, value] of Object.entries(params)) {
40
    if (value != null && value !== "") {
41
      url.searchParams.append(key, String(value))
42
    }
43
  }
44

45
  const response = await fetch(url, {
46
    headers: {
47
      Authorization: `Bearer ${auth.token}`,
48
      Accept: "application/json",
49
    },
50
  })
51

52
  if (!response.ok) {
53
    throw new Error(`${response.status} ${await response.text()}`)
54
  }
55

56
  return await response.json()
57
}
58

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 528 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