如何使用Python从Asana API访问自定义字段



我正在尝试从我的Asana列表中撤回自定义字段的值。我正在为Asana API V1使用官方的Python客户库库。

我的代码当前看起来像这样;

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

我得到输出;

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

"无"值的数量等于自定义字段的数量。如何获得关键名称和值?我的最终目标是验证值并更新为nessesary。

我已经进行了一些试验,并设法重现了您所遇到的问题。您可以尝试opt_fields":"this.name,custom_fields吗?

最新更新