<?php require_once '../asana.php'; // See class comments and Asana API for full info $asana = new Asana(array('apiKey' => 'XXXXXXXXXXXXXXXXXXX')); // Your API Key, you can get it in Asana $workspaceId = 'XXXXXXXXXXXXXXXXXXX'; // 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, 'name' => 'Hello World!', 'assignee' => '*****@*****.**')); // 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 }
<?php require_once '../asana.php'; // See class comments and Asana API for full info $asana = new Asana(array('personalAccessToken' => 'xxxxxxxxxxxxxxxxxxxxx')); // Create a personal access token in Asana or use OAuth $projectId = 'XXXXXXXXXXXXXXXXXXX'; // Your Project ID Key, you can get it in Asana $asana->getProjectTasks($projectId); // As Asana API documentation says, when response is successful, we receive a 200 in response so... if ($asana->hasError()) { echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode; return; } echo '<pre>'; var_dump($asana->getData()); echo '</pre>';
<?php require_once '../asana.php'; // See class comments and Asana API for full info $asana = new Asana(array('apiKey' => 'XXXXXXXXXXXXXXXXXXX')); // 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, 'name' => 'Hello World!', 'assignee' => '*****@*****.**', 'followers' => array('XXXXX', 'XXXXXXXX'))); // 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; } $taskId = $asana->getData()->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 $asana->addProjectToTask($taskId, $projectId); if ($asana->hasError()) { echo 'Error while assigning project to task: ' . $asana->responseCode; } else { echo 'Success to add the task to a project.'; }
$asanaAuth = new AsanaAuth('CLIENT_ID', 'CLIENT_SECRET', 'REDIRECT_URL'); if (!isset($_GET['code'])) { // We don't have the code so we need to authorize our app. // Get the url. $url = $asanaAuth->getAuthorizeUrl(); // Redirect the user to asana authorization url. header('Location:' . $url); // Now the user will authorize the app and this page will load again having the ?code parameter that we can use. } else { // We have authorization from the user. // We have to get the access token. $asanaAuth->getAccessToken($_GET['code']); // As Asana API documentation says, when response is successful, we receive a 200 in response so... if ($asanaAuth->hasError()) { echo 'Error while trying to connect to Asana to get the access token, response code: ' . $asanaAuth->responseCode; return; } $result = $asanaAuth->getData(); // Now we can create a normal asana object with the access token. $asana = new Asana(array('accessToken' => $result->access_token)); $asana->getProjects(); // As Asana API documentation says, when response is successful, we receive a 200 in response so... if ($asana->hasError()) { echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode; return; } // $asana->getData() contains an object in json with all projects foreach ($asana->getData() as $project) { echo 'Project ID: ' . $project->id . ' is ' . $project->name . '<br>' . PHP_EOL; } }
<?php require_once '../asana.php'; // See class comments and Asana API for full info $asana = new Asana(array('apiKey' => 'xxxxxxxxxxxxxxxxxxxxx')); // Your API Key, you can get it in Asana // Get all workspaces $asana->getWorkspaces(); // As Asana API documentation says, when response is successful, we receive a 200 in response so... if ($asana->hasError()) { echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode; return; } foreach ($asana->getData() as $workspace) { echo '<h3>*** ' . $workspace->name . ' (id ' . $workspace->id . ')' . ' ***</h3><br />' . PHP_EOL; // Get all projects in the current workspace (all non-archived projects) $asana->getProjectsInWorkspace($workspace->id, $archived = false); // As Asana API documentation says, when response is successful, we receive a 200 in response so... if ($asana->hasError()) { echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode; continue; } foreach ($asana->getData() as $project) { echo '<strong>[ ' . $project->name . ' (id ' . $project->id . ')' . ' ]</strong><br>' . PHP_EOL; // Get all tasks in the current project $asana->getProjectTasks($project->id); if ($asana->hasError()) { echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode; continue; } foreach ($asana->getData() as $task) {
<?php require_once '../asana.php'; // See class comments and Asana API for full info $asana = new Asana(array('apiKey' => 'XXXXXXXXXXXXX')); // Your API Key, you can get it in Asana $workspaceId = 42; // The workspace to dump to JSON // Get all projects in the current workspace (all non-archived projects) $asana->getProjectsInWorkspace($workspaceId, $archived = false); // As Asana API documentation says, when response is successful, we receive a 200 in response so... if ($asana->hasError()) { echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode; exit; } $projects = $asana->getData(); foreach ($projects as $project) { echo '<strong>[ ' . $project->name . ' (id ' . $project->id . ')' . ' ]</strong><br>' . PHP_EOL; //if ($project->id != 42) { // Quickly filter on a project // continue; //} // Get all tasks in the current project $asana->getProjectTasks($project->id); if ($asana->hasError()) { echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode; continue; } foreach ($asana->getData() as $task) { echo '+ ' . $task->name . ' (id ' . $task->id . ')' . ' ]<br>' . PHP_EOL; $asana->getTask($task->id); if (!$asana->hasError()) {