Edits history of script submission #3233 for ' Add task to section (asana)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Asana = {
      token: string;
    };
    /**
     * Add task to section
     * Add a task to a specific, existing section. This will remove the task from other sections of the project.
    
    The task will be inserted at the top of a section unless an insert_before or insert_after parameter is declared.
    
    This does not work for separators (tasks with the resource_subtype of section).
     */
    export async function main(
      auth: Asana,
      section_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      body: {
        data?: {
          insert_after?: string;
          insert_before?: string;
          task: string;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/sections/${section_gid}/addTask`
      );
      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;
    };
    /**
     * Add task to section
     * Add a task to a specific, existing section. This will remove the task from other sections of the project.
    
    The task will be inserted at the top of a section unless an insert_before or insert_after parameter is declared.
    
    This does not work for separators (tasks with the resource_subtype of section).
     */
    export async function main(
      auth: Asana,
      section_gid: string,
      opt_pretty: string | undefined,
      opt_fields: string | undefined,
      body: {
        data?: {
          insert_after?: string;
          insert_before?: string;
          task: string;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://app.asana.com/api/1.0/sections/${section_gid}/addTask`
      );
      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