zaump
zaump

Reputation: 157

Created Asana tasks via Python API in reverse order

I have a python script which imports a csv file into an Asana project, one task per row.

It works fine, except that it seems to create tasks in the opposite order from the web interface - ie: online, you create new tasks at the end of the list, but the API appears to create new tasks at the top.

Since the csv's are annoyingly structured (ie: sorted by presentation not by due date, broken into sections which I'm parsing at runtime, etc) the order does actually matter more than it ideally should.

So: is there an easy way to reverse the order so the API appends tasks at the end rather than inserting them at the top? Right now, I'm just reversing the csv when I import it, and it works okay, but it's ugly and inefficient and I wonder if I'm not missing something incredibly obvious :)

Any suggestions?

Upvotes: 1

Views: 379

Answers (1)

Andrew Noonan
Andrew Noonan

Reputation: 848

Tasks added to a project in the UI via the omni button, multi-homing, etc will also appear at the top of the project unless you are explicitly in the project its self, focused on the center pane task list and press "Enter" to add the new task. A bit confusing, I agree.

As for task ordering in the API, you are correct that new tasks added to a project will appear at the top of the project. You can alter the position of a task by calling POST /tasks/task-id/addProject and providing insert_before, insert_after, or section parameters with the ID of the task or section to move this task next to.

With the Asana python client the call looks like this:

`client.tasks.add_project(<TASK_ID>, { 'project' : <PROJECT_ID>, 'insert_after' : <PRECEDING_TASK> })`

You can also specify the memberships property of a task when creating in order to dictate the section a task should appear in.

To be honest, your current solution is probably the best, in the future we may allow you to specify the neighboring task upon creation. In that case you could specify the ID from each response in the insert_after of each create to get reverse order. I will add that to our list of requests.

Upvotes: 1

Related Questions