Edits history of script submission #23695 for ' Create Section (asana)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    
    /**
     * Create Section
     * Create a section (a board column, or a heading in list view) in a project. Without insert_before/insert_after it is added at the end.
     */
    export async function main(
      auth: RT.Asana,
      project_gid: string,
      name: string,
      insert_before: string | undefined,
      insert_after: string | undefined
    ) {
      const response = await fetch(
        `https://app.asana.com/api/1.0/projects/${project_gid}/sections`,
        {
          method: "POST",
          headers: {
            Authorization: `Bearer ${auth.token}`,
            "Content-Type": "application/json",
            Accept: "application/json",
          },
          body: JSON.stringify({
            data: {
              name,
              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