2013-04-06 52 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