如何使用Python从Asana API访问自定义字段? [英] How can I access custom fields from Asana API using Python?

查看:210
本文介绍了如何使用Python从Asana API访问自定义字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Asana列表中下拉自定义字段的值.我正在使用 Asana API v1的官方Python客户端库.

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

我得到了输出;

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.

推荐答案

我做了一些尝试,设法重现了您遇到的问题.您可以尝试opt_fields":"this.name,custom_fields吗?

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

这篇关于如何使用Python从Asana API访问自定义字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆