i want to use Asana-Api by using PHP-Asana (GitHub - Asana/php-asana: Official PHP client library for the Asana API v1).
I’m connecting via $client = Asana\Client::accessToken(); That works.
Creating a Project or Task is also working.
$project = $client->projects->createInWorkspace($workspace, array('name' => 'demo project'));
$demoTask = $client->tasks->createInWorkspace($workspace, array(
"name" => "demo task aa at " . date('m/d/Y h:i:s a'),
"projects" => array($project->id)));
With the response i want to add a subtask, follower or comment, e.g.
$client->tasks->addSubtask($demoTask->id, array("name" => "subtask"));
$client->tasks->addComment($demoTask->id, array("text" => "bla"));
Both examples don’t work.
The error is “Invalid Request”. I’m using the API in a Joomla-Project, with PHP 5.6
At first I thought, the problem might be the json-response of PHP 5.6 ($demoTask->id like XXXXX+E14) But the $project->id is in this format too.
thanks for your ideas!
I am a bit surprised you are passing an array, I would expect addSubtask to take an object instead with key-value pairs, but maybe that’s how PHP works.
Anyway, the answer invalid request always has details about what’s the issue. Can you share it here?
It looks like you are trying to add a subtask to your demo task!
For this I use the createSubtaskForTask() function.
//Notes: I have to pass in the user because I am running this as a job.
//You should be able to scrap everything untill ->tasks and put your bit infront
//for you it should be
$client->tasks->createSubtaskForTask($task->gid, ['name' => 'name', 'notes' => 'description'])
$this->task,//Note, This it the Task GID
'name' => $this->name,
'notes' => $this->notes,
'resource_subtype' => $this->subtype,
This is code from my little application… And it works. I am working with Laravel and the code is from a job to run in the background. So I am using
$this->var These are just values I get from the form somewhere else/ Just replaces them with what you want it to be… Or scrap those you dont want, You can add the same fields to the array as you can on createTask
Let me know if this helps