0

Delete a goal

Published Oct 31, 2023

A specific, existing goal can be deleted by making a DELETE request on the URL for that goal. Returns an empty data record.

Script asana
  • Submitted by hugo697 Typescript (fetch-only)
    Created 566 days ago
    1
    type Asana = {
    2
      token: string;
    3
    };
    4
    /**
    5
     * Delete a goal
    6
     * A specific, existing goal can be deleted by making a DELETE request on the URL for that goal.
    7
    
    
    8
    Returns an empty data record.
    9
     */
    10
    export async function main(
    11
      auth: Asana,
    12
      goal_gid: string,
    13
      opt_pretty: string | undefined,
    14
      opt_fields: string | undefined
    15
    ) {
    16
      const url = new URL(`https://app.asana.com/api/1.0/goals/${goal_gid}`);
    17
      for (const [k, v] of [
    18
        ["opt_pretty", opt_pretty],
    19
        ["opt_fields", opt_fields],
    20
      ]) {
    21
        if (v !== undefined && v !== "") {
    22
          url.searchParams.append(k, v);
    23
        }
    24
      }
    25
      const response = await fetch(url, {
    26
        method: "DELETE",
    27
        headers: {
    28
          Authorization: "Bearer " + auth.token,
    29
        },
    30
        body: undefined,
    31
      });
    32
      if (!response.ok) {
    33
        const text = await response.text();
    34
        throw new Error(`${response.status} ${text}`);
    35
      }
    36
      return await response.json();
    37
    }
    38