I am using a simple php script which generates a task's name (it is quite long, that's why I build a generator for generating it). Right now I need to copy generated name to ASANA, while I am creating a new task but I know that using ASANA API it can be integrated with my generator (when I click on GENERATE button the project's name is generated and a new ASANA task has been created with the generated name).
I created in my dashboard a Personal access token.
I downloaded this library https://github.com/ajimix/asana-api-php-class and filled up file examples/task-creation.php
(all 3 fields with capital letters are correct filled):
<?php
require_once('../asana.php');
// See class comments and Asana API for full info
$asana = new Asana(array('personalAccessToken' => 'MY PERSONAL ACCESS TOKEN')); // Create a personal access token in Asana or use OAuth
$workspaceId = 'MY WORKSPACE ID'; // The workspace where we want to create our task, take a look at getWorkspaces() method.
// First we create the task
$asana->createTask(array(
'workspace' => $workspaceId, // Workspace ID
'name' => 'Hello World!', // Name of task
'assignee' => 'HERE MY EMAIL' // Assign task to...
));
// As Asana API documentation says, when a task is created, 201 response code is sent back so...
if ($asana->hasError()) {
echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
return;
}
$result = $asana->getData();
if (isset($result->id)) {
echo $result->id; // Here we have the id of the task that have been created
}
?>
After running the script from my localhost
directory I get following error:
Error while trying to connect to Asana, response code: 0
Any help regarding this problem will be appreciated.
Please move your file to an online host instead of localhost. It should work.