0

List Sections

by
Published Oct 31, 2023

List the sections of a project, in board column / list order. 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
/**
4
 * List Sections
5
 * List the sections of a project, in board column / list order. Pass `next_page.offset` from a response as `offset` to get the next page.
6
 */
7
export async function main(
8
  auth: RT.Asana,
9
  project_gid: string,
10
  opt_fields: string | undefined,
11
  limit: number | undefined,
12
  offset: string | undefined
13
) {
14
  const url = new URL(
15
    `https://app.asana.com/api/1.0/projects/${project_gid}/sections`
16
  )
17
  const params = { opt_fields, limit: limit ?? 100, offset }
18
  for (const [key, value] of Object.entries(params)) {
19
    if (value != null && value !== "") {
20
      url.searchParams.append(key, String(value))
21
    }
22
  }
23

24
  const response = await fetch(url, {
25
    headers: {
26
      Authorization: `Bearer ${auth.token}`,
27
      Accept: "application/json",
28
    },
29
  })
30

31
  if (!response.ok) {
32
    throw new Error(`${response.status} ${await response.text()}`)
33
  }
34

35
  return await response.json()
36
}
37

Other submissions
  • Submitted by hugo697 Typescript (fetch-only)
    Created 528 days ago
    1
    type Asana = {
    2
      token: string;
    3
    };
    4
    /**
    5
     * Get sections in a project
    6
     * Returns the compact records for all sections in the specified project.
    7
     */
    8
    export async function main(
    9
      auth: Asana,
    10
      project_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/projects/${project_gid}/sections`
    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