2013-04-06 20 views
1

我似乎试图使用Asana API卡住了。我正在尝试在特定项目上发布任务。通过CURL发布特定项目的任务

这里就是我想:

$api = 'myapikey'; 
$url = 'https://app.asana.com/api/1.0/tasks'; 

$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, $url); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // Don't print the result 
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30); 
curl_setopt($curl, CURLOPT_TIMEOUT, 30); 
curl_setopt($curl, CURLOPT_FAILONERROR, true); 
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // Don't verify SSL connection 
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); //   ""   "" 
curl_setopt($curl, CURLOPT_USERPWD, $api); 
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json")); 
$data = array(
    "data" => array(
     "workspace" => "workspace id", 
     "name" => "Task Name", 
     "notes" => "notes", 
     "assignee" => "assignee id" 
    ) 
); 
$data = json_encode($data); 
curl_setopt($curl, CURLOPT_POST, true); 
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);   
$html = curl_exec($curl); 
curl_close($curl); 

$html = json_decode($html); 
var_dump($html); 

它没有工作,它创建Undefined Project任务。我试着用以下变化:

  1. $url = 'https://app.asana.com/api/1.0/projects/4649161839339/tasks';

  2. $url = 'https://app.asana.com/api/1.0/tasks/projects/4649161839339';

任何想法?

回答

2

通过指定projects字段,您可以在创建时将任务添加到任务,该字段由用于将任务添加到的项目ID数组组成,例如:"projects" => [4649161839339],。这应该包含在开发者文档中。

对于PHP

$data = array(
    "data" => array(
     "workspace" => "workspace id", 
     "projects" => array('project_id'), 
     "name" => "Task Name", 
     "notes" => "notes", 
     "assignee" => "assignee id" 
    ) 
); 

一旦任务创建,您可以使用/tasks/ID/addProject/tasks/ID/removeProject端点添加和删除的项目。

+0

嗯,我没有找到它。我会试试这个。 – Starx 2013-04-13 02:28:42

+0

您应该考虑将其添加到文档中。 – Starx 2013-04-13 02:44:17