Edits history of script submission #23697 for ' Add Project to Task (asana)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Add Project to Task
     * Add a task to a project, optionally in a given section or next to another task. Calling it again for the same project moves the task.
     */
    export async function main(
      auth: RT.Asana,
      task_gid: string,
      project: string,
      section: string | undefined,
      insert_before: string | undefined,
      insert_after: string | undefined
    ) {
      const response = await fetch(
        `https://app.asana.com/api/1.0/tasks/${task_gid}/addProject`,
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify({
            data: {
              project,
              section: section || undefined,
              insert_before: insert_before || undefined,
              insert_after: insert_after || undefined,
            },
          }),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 3 hours ago