0

Removes a supporting goal relationship

Published Oct 31, 2023

Removes a goal relationship for a given parent goal.

Script asana
  • Submitted by hugo697 Typescript (fetch-only)
    Created 568 days ago
    1
    type Asana = {
    2
      token: string;
    3
    };
    4
    /**
    5
     * Removes a supporting goal relationship
    6
     * Removes a goal relationship for a given parent goal.
    7
     */
    8
    export async function main(
    9
      auth: Asana,
    10
      goal_gid: string,
    11
      opt_pretty: string | undefined,
    12
      opt_fields: string | undefined,
    13
      body: {
    14
        data?: { supporting_resource: string; [k: string]: unknown };
    15
        [k: string]: unknown;
    16
      }
    17
    ) {
    18
      const url = new URL(
    19
        `https://app.asana.com/api/1.0/goals/${goal_gid}/removeSupportingRelationship`
    20
      );
    21
      for (const [k, v] of [
    22
        ["opt_pretty", opt_pretty],
    23
        ["opt_fields", opt_fields],
    24
      ]) {
    25
        if (v !== undefined && v !== "") {
    26
          url.searchParams.append(k, v);
    27
        }
    28
      }
    29
      const response = await fetch(url, {
    30
        method: "POST",
    31
        headers: {
    32
          "Content-Type": "application/json",
    33
          Authorization: "Bearer " + auth.token,
    34
        },
    35
        body: JSON.stringify(body),
    36
      });
    37
      if (!response.ok) {
    38
        const text = await response.text();
    39
        throw new Error(`${response.status} ${text}`);
    40
      }
    41
      return await response.json();
    42
    }
    43