Re-ordering subtasks using Batch API

Re-ordering subtasks using Batch API

hi everyone,

I’m facing an issue with the Asana Batch API while trying to re-order subtasks. Initially, I create a milestone and then add subtasks to it via batch API, which results in the subtasks being in an unordered list – this is expected, I’m good with this. However, my goal is to organize these subtasks in a specific order after they have been created.

To achieve this, I’ve been attempting to use the asana.BatchAPIApi to re-order the subtasks, but unfortunately, it isn’t working as expected. I believe the issue is specifically related to the use of the batch API for setting the parent or order of the subtasks. If anyone has experience with this or has managed to successfully re-order subtasks using the batch API, I would greatly appreciate your insights or advice on how to resolve this issue.

def reorder_subtasks(self, sorted_task_gids: list[str])
        batch_api = asana.BatchAPIApi(self.api_client)
        actions = [
                "method": "POST",
                "relative_path": f"tasks/{child_gid}/setParent",
                "data": {
                    "parent": parent_task_gid,
                    "insert_after": sorted_task_gids[prev_item_index],
            } for prev_item_index, child_gid in enumerate(sorted_task_gids[1:])

        chunked_actions = [actions[i:i + 10] for i in range(0, len(actions), 10)]
        for chunk in chunked_actions:
            opts = {"fields": ["body"]}
            _batch_response = batch_api.create_batch_request({"data": {"actions": chunk}}, opts)

I can provide more – a minimum reproducible example if needed, but I hope the description is sufficient to start a discussion. Thank you :pray:

Hi @mira7 and welcome to the forum,

You won’t be able to use the Batch API for this because, per the documentation:

There is no guarantee of the execution order for these actions

You can’t know in what order the API will execute your actions within the batch. You’ll have to issue individual API calls so they run in the exact order you need.


@Phil_Seeman, thank you for your swift reply.

Understood, that was my assumption, but I didn’t think it is the cause. So, ordering should be done in order :smile:

Then sequential requests with setParent it is.
Although this is very unfortunate – I was trying to limit the amount of outgoing requests to Asana.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.