I am using Asana API PHP class, hosted here: https://github.com/ajimix/asana-api-php-class
And I am using their almost exact sample code:
<?php
// See class comments and Asana API for full info
$asana = new Asana(array('apiKey' => 'xxxxxxxxxxxxxxxxxxxxxxxx')); // Your API Key, you can get it in Asana
$workspaceId = 'XXXXXXXXXXXXXXXXXXX'; // The workspace where we want to create our task
$projectId = 'XXXXXXXXXXXXXXXXXXX'; // The project where we want to save our task
// First we create the task
$result = $asana->createTask(array(
'workspace' => $workspaceId, // Workspace ID
'name' => 'Hello World!', // Name of task
'assignee' => 'bigboss@bigcompany.com', // Assign task to...
'followers' => array('XXXXX', 'XXXXXXXX') // We add some followers to the task... (this time by ID), this is totally optional
));
// As Asana API documentation says, when a task is created, 201 response code is sent back so...
if ($asana->responseCode != '201' || is_null($result)) {
echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
return;
}
$resultJson = json_decode($result);
$taskId = $resultJson->data->id; // Here we have the id of the task that have been created
// Now we do another request to add the task to a project
$result = $asana->addProjectToTask($taskId, $projectId);
if ($asana->responseCode != '200') {
echo 'Error while assigning project to task: ' . $asana->responseCode;
}
Changes I made to this original code:
- I got my API key from Asana, so I am assuming it should be nothing wrong with it, and put it inside the
apiKey
array index - I don't actually know what the workspace ID is, but the URL of my project is in the format of
https://app.asana.com/{integer}/{integer}/{integer}
, so I used the first integer as the$workspaceId
and the second one (which is the same as the third one) as the$projectId
. I also tried using the second integer as both the$projectId
and the$workspaceId
with the same outcome - I put my own Asana email under the
assignee
array index in thecreateTask()
call - I removed the
followers
array item from thecreateTask()
call
With only those changes, and then running this code, I get Error while trying to connect to Asana, response code: 400
. No further error code explanations or a FAQ are available on the Asana page. What could be the problem?