1

我似乎在尝试使用 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';

任何的想法?

4

1 回答 1

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端点添加和删除项目。

于 2013-04-12T18:29:09.467 回答