如何通过python体式api上传项目下的体式任务?

How to upload an asana task under a project via the python asana api?

asana documentation 说明您可以使用以下代码在工作区内创建任务,该代码有效:

workspace_id = '48673284270301'
client = asana.Client.basic_auth('asana_api')
client.tasks.create_in_workspace(workspace_id,{ 'name': 'new task'})

我也知道你可以用下面的代码创建一个项目:

client = asana.Client.basic_auth('asana_api')
client.projects.create_in_workspace(workspace_id,{'name': 'new project'} )

但是我想不通怎么上传某个项目下的任务?

我试过以下方法:

workspace_id = '48673284270301'
client = asana.Client.basic_auth('asana_api')
client.tasks.create_in_workspace(workspace_id,{ 'name': 'new task','projects':[{'id':48729403436686,'name': u'Larry (2100 Walnut)'}]})

这向我发送了以下错误:

  File "build/bdist.macosx-10.6-x86_64/egg/asana/resources/_tasks.py", line 78, in create_in_workspace
  File "build/bdist.macosx-10.6-x86_64/egg/asana/client.py", line 100, in post
  File "build/bdist.macosx-10.6-x86_64/egg/asana/client.py", line 60, in request
asana.error.InvalidRequestError: Invalid Request: projects: [0]: Not a recognized ID: [object Object]

在 API 中的任何地方引用对象时,您需要使用的是该对象的全局唯一标识符。

如果您将代码更改为在创建任务时仅引用项目 ID,我认为它应该可以工作

client = asana.Client.basic_auth('asana_api')
client.tasks.create_in_workspace(workspace_id,{ 'name': 'new task','projects':[project_id]})

此外,我添加了 another example to the python-asana library 来演示在特定项目中创建任务。