Edits history of script submission #23689 for ' Update Project (asana)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Update Project
     * Update a project. Only the fields you set are changed. `archived` defaults to `keep`. Dates as YYYY-MM-DD.
     */
    export async function main(
      auth: RT.Asana,
      project_gid: string,
      name: string | undefined,
      notes: string | undefined,
      html_notes: string | undefined,
      owner: string | undefined,
      color: string | undefined,
      start_on: string | undefined,
      due_on: string | undefined,
      archived: "keep" | "archive" | "unarchive" = "keep"
    ) {
      const data: { [key: string]: any } = {
        name: name || undefined,
        notes: notes || undefined,
        html_notes: html_notes || undefined,
        owner: owner || undefined,
        color: color || undefined,
        start_on: start_on || undefined,
        due_on: due_on || undefined,
      }
      if (archived === "archive") data.archived = true
      if (archived === "unarchive") data.archived = false
    
      const response = await fetch(
        `https://app.asana.com/api/1.0/projects/${project_gid}`,
        {
          method: "PUT",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify({ data }),
        }
      )
    
      if (!response.ok) {
        throw new Error(`${response.status} ${await response.text()}`)
      }
    
      return await response.json()
    }
    

    Submitted by hugo989 3 hours ago