How can I access custom fields from Asana API using Python?

时光毁灭记忆、已成空白 提交于 2019-12-25 08:09:08

问题


I'm trying to pull down the values of custom fields from my Asana list. I'm using the Official Python client library for the Asana API v1.

My code currently looks like this;

import asana

api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
client = asana.Client.basic_auth(api_key)
me = client.users.me()
all_projects = next(workspace for workspace in me['workspaces'])
projects = client.projects.find_by_workspace(all_projects['id'])

for project in projects:
    if 'Example Project' not in project['name']:
        continue
    tasks = client.tasks.find_by_project(project['id'], {"opt_fields":"this.name,this.custom_fields"}, iterator_type=None)

    for task in tasks:
        if "Example Task" in task['name']:
            print "Matching task found."
            print task['name'] + " - " + str(task['id'])
            print task['custom_fields']
            print

I get the output;

Matching task found.
Example Task - 228660596773016
[None, None]

Matching task found.
Example Task 2 - 228660596773021
[None, None]

The number of "None" values is equal to the number of custom fields. How can I get the key name and the value? My ultimate goal is to verify the value and update as nessesary.


回答1:


I've experimented a little and managed to reproduce the issue you're having. Can you try opt_fields":"this.name,custom_fields?



来源:https://stackoverflow.com/questions/41093759/how-can-i-access-custom-fields-from-asana-api-using-python

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!