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

时间:2015-09-11 02:02:35

标签: python api rest asana

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]

1 个答案:

答案 0 :(得分:0)

当引用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,演示了如何在特定项目中创建任务。