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