通过CURL在特定项目上发布任务

时间:2013-04-06 15:10:31

标签: php asana

我似乎一直试图使用Asana API。我正在尝试在特定项目上发布任务

以下是我的尝试:

$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';

  3. 任何想法?

1 个答案:

答案 0 :(得分: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端点添加和删除项目。