0

Get goals

Published Oct 31, 2023

Returns compact goal records.

Script asana
  • Submitted by hugo697 Typescript (fetch-only)
    Created 566 days ago
    1
    type Asana = {
    2
      token: string;
    3
    };
    4
    /**
    5
     * Get goals
    6
     * Returns compact goal records.
    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
      portfolio: string | undefined,
    15
      project: string | undefined,
    16
      is_workspace_level: string | undefined,
    17
      team: string | undefined,
    18
      workspace: string | undefined,
    19
      time_periods: string | undefined
    20
    ) {
    21
      const url = new URL(`https://app.asana.com/api/1.0/goals`);
    22
      for (const [k, v] of [
    23
        ["opt_pretty", opt_pretty],
    24
        ["opt_fields", opt_fields],
    25
        ["limit", limit],
    26
        ["offset", offset],
    27
        ["portfolio", portfolio],
    28
        ["project", project],
    29
        ["is_workspace_level", is_workspace_level],
    30
        ["team", team],
    31
        ["workspace", workspace],
    32
        ["time_periods", time_periods],
    33
      ]) {
    34
        if (v !== undefined && v !== "") {
    35
          url.searchParams.append(k, v);
    36
        }
    37
      }
    38
      const response = await fetch(url, {
    39
        method: "GET",
    40
        headers: {
    41
          Authorization: "Bearer " + auth.token,
    42
        },
    43
        body: undefined,
    44
      });
    45
      if (!response.ok) {
    46
        const text = await response.text();
    47
        throw new Error(`${response.status} ${text}`);
    48
      }
    49
      return await response.json();
    50
    }
    51