Adding a task to (the top of a) section

I have seen in a previous API reference doc that when moving a task to a different section it was inserted at the top. However, the current behavior and doc states the opposite: “the task will be inserted at the bottom of the section”.

Is there a way to revert that or to specify the position of the task in the new section? _insert_after_and insert_before seem to only apply to lists, no boards.

Thanks!

Background: at the Done section, when the tasks are automatically moved to the bottom makes it visually harder to grasp/understand which were the latest completed tasks in a project

These parameters should work equally well for a board project.

  • insert_after = null puts the task at the top of the first board
  • insert_before = null puts the task at the end of the last board
  • You can’t specify section and insert_before in the same call.

It seems the only way to put it at the top of the section is first retrieving all tasks in a board and, after getting the id from the one at the top, using that id with the insert_before param. Which feels like a lot of api calls while before the API update it had the desired (and kind of expected) behaviour.

This action (adding a task to the top of a section) should be possible in our API. The API route is supposed to be POST /sections/<section-id>/addTask which would take task as a required parameter and insert_before and insert_after as optional parameters. However, we never exposed this route because we were (and still are) wary about exposing endpoints that have different behaviors for the two different kinds of “sections.”

Now that we are deprecating task-sections this world becomes drastically simpler. We will eventually be exposing this route, and I’ll update this thread when it’s live in production.

That makes a lot of sense. Thanks @Joe_Trollo for the clarification!

Hey @Rubs, POST /sections/<section-id>/addTask is now live in production. The endpoint will take in a task as a required parameter and insert_before and insert_after as optional parameters. If one of insert_before or insert_after are not provided, the task will be inserted to the top of the section by default.

Note that since we are deprecating task-sections, this endpoint will not accept them as valid sections.

1 Like

Thanks @Kevin_Quicho for the update! Will test that endpoint as soon as I can.

@Kevin_Quicho Sounds awesome! Can you give details when this feature will be available for all? I just tested it and the console threw an error that this feature is not implemented yet.

@Kevin_Quicho @Joe_Trollo It looks like the docs are not up to date with the actual API. Took me some time to realize the docs were wrong, and your posts were correct…

The docs are in a section misleadingly called MOVE A SECTION IN A PROJECT and it says the API call is: POST /sections/{task_gid}/addTask where it should really be {section_id} as you say. Also, the required task parameter should be listed in the Parameters section. The error message when you leave out the task parameter (because I was setting task_gid instead…) wasn’t as helpful as it could have been.

The “Explorer” tab doesn’t include the sections resource at all, either. FYI.

Hi @Tim_Oertel, thanks for pointing that out. We’ve recently moved our docs over here and the true docs should have the correct information.

tried this
{

“data”: {

"insert_after": "123",

"insert_before": "789",

"task": "4126"

}

}
response bad reequest
{

"errors": [

    {

        "error": "ranked_list_at_most_one_of_before_or_after",

        "message": "You can specify at most one of insert_before or insert_after.",

        "user_message": "You can specify at most one of insert_before or insert_after.",

        "help": "For more information on API status codes and how to handle them, read the docs on errors: https://developers.asana.com/docs/errors"

    }

]

}
also tried with null still same response

please help

@Soham_Jain,

It should put the task at the top of the section by default. If you omit both insert_before and insert_after, where does it put the task?

i tried to create task , and its creating task on top of 1st section.

But i want to move it to top of 2nd section in my project at top.
i tried giving both the values one by one but still its not moving to 2nd section.

As in the above example i m trying to move the Task taskid(456)
between task TaskId(123) and task TaskId(789).

it will be great if u help me with example/code correction

@Phil_Seeman can you please help me on it ?

Hi @Soham_Jain,

I just ran this in Postman to verify what I said above. If you call this endpoint:

{baseUrl}/sections/{section_gid}/addTask

where {section_gid} is the gid of the section where you want to move a task to,

and in the body, just pass the task gid and omit both insert_before and "insert_after`, like so:

{
    "data": {
        "task": "1201753339871518"
    }
}

then it will move that task into that section and place it at the top of the section.