Using API batch operation in Python


I’m updating many tasks via python script and want to use batch update in order to improve performance.
I wasn’t able to find example for that, any ideas where could I find one?

Guys, bumping up … help please?

Hi @Sharon_Cohen-Ofir ,

I’m sorry for the very late response.
Despite this comment, it seems the example was deleted from the API doc :astonished:

Here’s part of my Python code I wrote in the past using batch API:

client = asana.Client.access_token(os.environ['ASANA_ACCESS_TOKEN'])
client.headers = {'Asana-Enable': 'string_ids,new_sections', 'Asana-Fast-Api': 'True'}
response_all_tags, response_all_users ='/batch', {'actions': [
    {'method': 'get', 'relative_path': '/workspaces/' + some_data_source.data_str_workspace_gid + '/tags'},
    {'method': 'get', 'relative_path': '/workspaces/' + some_data_source.data_str_workspace_gid + '/users', 'options': {'fields': ['email']}}

def add_subtasks_batch(list_assignees_and_names, task_gid):'/batch', {'actions': [{'method': 'post', 'relative_path': '/tasks/' + task_gid + '/subtasks', 'data': assignee_and_name} for assignee_and_name in list_assignees_and_names]})

if list_user_tags_gid:
    list_actions_add_tags = [{'method': 'post', 'relative_path': '/tasks/' + task_gid + '/addTag', 'data': {'tag': user_tag_gid}} for user_tag_gid in list_user_tags_gid]'/batch', {'actions': list_actions_add_tags})