Edits history of script submission #3223 for ' Create a goal metric (asana)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Asana = {
      token: string;
    };
    /**
     * Create a goal metric
     * Creates and adds a goal metric to a specified goal. Note that this replaces an existing goal metric if one already exists.
     */
    export async function main(
      auth: Asana,
      goal_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      body: {
        data?: { gid?: string; resource_type?: string; [k: string]: unknown } & {
          currency_code?: string;
          current_display_value?: string;
          current_number_value?: number;
          initial_number_value?: number;
          precision?: number;
          progress_source?:
            | "manual"
            | "subgoal_progress"
            | "project_task_completion"
            | "project_milestone_completion"
            | "external";
          resource_subtype?: "number";
          target_number_value?: number;
          unit?: "none" | "currency" | "percentage";
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/goals/${goal_gid}/setMetric`
      );
      for (const [k, v] of [
        ["opt_pretty", opt_pretty],
        ["opt_fields", opt_fields],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 383 days ago

  • nativets
    type Asana = {
      token: string;
    };
    /**
     * Create a goal metric
     * Creates and adds a goal metric to a specified goal. Note that this replaces an existing goal metric if one already exists.
     */
    export async function main(
      auth: Asana,
      goal_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      body: {
        data?: { gid?: string; resource_type?: string; [k: string]: unknown } & {
          currency_code?: string;
          current_display_value?: string;
          current_number_value?: number;
          initial_number_value?: number;
          precision?: number;
          progress_source?:
            | "manual"
            | "subgoal_progress"
            | "project_task_completion"
            | "project_milestone_completion"
            | "external";
          resource_subtype?: "number";
          target_number_value?: number;
          unit?: "none" | "currency" | "percentage";
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/goals/${goal_gid}/setMetric`
      );
      for (const [k, v] of [
        ["opt_pretty", opt_pretty],
        ["opt_fields", opt_fields],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 937 days ago