Edits history of script submission #3268 for ' Get a user's favorites (asana)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Asana = {
      token: string;
    };
    /**
     * Get a user's favorites
     * Returns all of a user's favorites in the given workspace, of the given type.
    Results are given in order (The same order as Asana's sidebar).
     */
    export async function main(
      auth: Asana,
      user_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      resource_type:
        | "portfolio"
        | "project"
        | "tag"
        | "task"
        | "user"
        | "project_template"
        | undefined,
      workspace: string | undefined
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/users/${user_gid}/favorites`
      );
      for (const [k, v] of [
        ["opt_pretty", opt_pretty],
        ["opt_fields", opt_fields],
        ["resource_type", resource_type],
        ["workspace", workspace],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      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;
    };
    /**
     * Get a user's favorites
     * Returns all of a user's favorites in the given workspace, of the given type.
    Results are given in order (The same order as Asana's sidebar).
     */
    export async function main(
      auth: Asana,
      user_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      resource_type:
        | "portfolio"
        | "project"
        | "tag"
        | "task"
        | "user"
        | "project_template"
        | undefined,
      workspace: string | undefined
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/users/${user_gid}/favorites`
      );
      for (const [k, v] of [
        ["opt_pretty", opt_pretty],
        ["opt_fields", opt_fields],
        ["resource_type", resource_type],
        ["workspace", workspace],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 937 days ago