Read Asana API documentation for fully use this class http://developer.asana.com/documentation/ Copyright 2012 Ajimix Licensed under the Apache License 2.0 Author: Ajimix [github.com/ajimix] Version: 1.0
Exemplo n.º 1
2
    echo "{$proj}";
    if ($proj == "projectid_1") {
        $projselect = XXXXXXXXXXXXX;
    }
    if ($proj == "projectid_2") {
        $projselect = XXXXXXXXXXXXX;
    }
    if ($proj == "projectid_3") {
        $projselect = XXXXXXXXXXXXX;
    }
    if ($proj == "projectid_4") {
        $projselect = XXXXXXXXXXXXX;
    }
    if ($proj == "projectid_5") {
        $projselect = XXXXXXXXXXXXX;
    }
    echo "{$projselect}";
}
// See class comments and Asana API for full info
$asana = new Asana(array('apiKey' => 'XXXXXXXXXXXXXXXXXXXXXXXXXX'));
// Your API Key, you can get it in Asana
$projectId = $projselect;
// Your Project ID Key, you can get it in Asana
$result = $asana->getProjectTasks($projectId);
// As Asana API documentation says, when response is successful, we receive a 200 in response so...
if ($asana->responseCode != '200' || is_null($result)) {
    echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
    return;
}
$resultJson = json_decode($result, true);
//var_dump($resultJson);
Exemplo n.º 2
0
<?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)
$projectsJson = $asana->getProjectsInWorkspace($workspaceId, $archived = false);
// As Asana API documentation says, when response is successful, we receive a 200 in response so...
if ($asana->responseCode != '200' || is_null($projectsJson)) {
    echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
    exit;
}
$projects = json_decode($projectsJson);
foreach ($projects->data 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
    $tasks = $asana->getProjectTasks($project->id);
    $tasksJson = json_decode($tasks);
    if ($asana->responseCode != '200' || is_null($tasks)) {
        echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
        continue;
    }
    $project->tasks = $tasksJson;
    foreach ($tasksJson->data as $task) {
        echo '+ ' . $task->name . ' (id ' . $task->id . ')' . ' ]<br>' . PHP_EOL;
<?php

/*
 * This file is part of the Showpad PHP API connection class from Jeroen Desloovere.
 *
 * For the full copyright and license information, please view the license
 * file that was distributed with this source code.
 */
// required to load
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/credentials.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->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') {
Exemplo n.º 4
0
<?php

ini_set("max_execution_time", 300);
require_once 'asana.php';
$asana = new Asana(array('apiKey' => 'bZN6mBeL.7cBWsHfKEMSPcNP4gmRHiIq'));
$workspaces = $asana->getWorkspaces();
$workspacesJson = json_decode($workspaces);
?>

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>ASANA Projects</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/bootstrap.css">
<style>
 body {
 padding-top: 10px;
 padding-bottom: 10px;
 }
</style>
<link rel="stylesheet" href="assets/style.css">
<script src="assets/bootstrap.js"></script>
<script src="assets/jquery.js"></script>
</head>
<?php

require_once '../asana.php';
// See class comments and Asana API for full info
$asana = new Asana(array('apiKey' => 'XXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXX'));
// Your API Key, you can get it in Asana
$taskId = 10924433056204.0;
$resultJson = $asana->getTask($taskId);
// As Asana API documentation says, when response is successful, we receive a 200 in response so...
if ($asana->responseCode != '200' || is_null($resultJson)) {
    echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
    return;
}
$task = json_decode($resultJson);
echo "Task details:" . PHP_EOL;
var_dump($task);
$resultJson = $asana->getTaskStories($taskId);
// As Asana API documentation says, when response is successful, we receive a 200 in response so...
if ($asana->responseCode != '200' || is_null($resultJson)) {
    echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
    return;
}
$stories = json_decode($resultJson);
echo "Task stories(comments):" . PHP_EOL;
var_dump($stories);
Exemplo n.º 6
0
            $ws->selected = true;
        }
    }
} else {
    $model['no_workspace'] = true;
    goto render;
}
$model["projects"] = Asana::projects($_REQUEST['workspace']);
if (!empty($_REQUEST['project'])) {
    foreach ($model["projects"] as &$p) {
        if ($p->id == $_REQUEST['project']) {
            $p->selected = true;
        }
    }
} else {
    $model['no_project'] = true;
    goto render;
}
if ($_REQUEST['project'] == 'me') {
    $model["tasks"] = Asana::tasks("me", null, $_REQUEST['workspace']);
    $model["me"] = true;
} else {
    $model["tasks"] = Asana::tasks(null, $_REQUEST['project'], $_REQUEST['workspace']);
}
foreach ($model["tasks"] as &$t) {
    if (substr($t->name, -1) == ":") {
        $t->title = true;
    }
}
render:
render("tasks", $model);
Exemplo n.º 7
0
<?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) {
Exemplo n.º 8
0
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.
    $result = $asanaAuth->getAccessToken($_GET['code']);
    // As Asana API documentation says, when response is successful, we receive a 200 in response so...
    if ($asanaAuth->responseCode != '200' || is_null($result)) {
        echo 'Error while trying to connect to Asana to get the access token, response code: ' . $asanaAuth->responseCode;
        return;
    }
    $resultJson = json_decode($result);
    // Now we can create a normal asana object with the access token.
    $asana = new Asana(array('accessToken' => $resultJson->access_token));
    $result = $asana->getProjects();
    // As Asana API documentation says, when response is successful, we receive a 200 in response so...
    if ($asana->responseCode != '200' && is_null($result)) {
        echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
        return;
    }
    $resultJson = json_decode($result);
    // $resultJson contains an object in json with all projects
    foreach ($resultJson->data as $project) {
        echo 'Project ID: ' . $project->id . ' is ' . $project->name . '<br>' . PHP_EOL;
    }
}
Exemplo n.º 9
0
<?php

require "../lib/load.php";
$model = ["workspaces" => Asana::workspaces()];
render("workspaces", $model);
Exemplo n.º 10
0
 } else {
     $conj = "an";
 }
 # task name
 $taskname = 'LDMS ' . $document->direction . ' (' . date_mysql2german($document->date) . '): ' . $document->mt . ' ' . $conj . ' ' . $document->external_party;
 $filepath = BASE_PATH . '/' . ARCHIVE_FOLDER_REL . '/' . $document->internal_party . '/' . date_german2yearonly(date_mysql2german($document->date)) . '/' . date_german2monthonly(date_mysql2german($document->date)) . '/' . $document->mailtype . '/' . date_german2ldms(date_mysql2german($document->date)) . '_' . $document->direction . '_' . $document->mailtype . '_' . $document->externalID . '_' . $document->internalID . '_' . $document->number . '.pdf';
 # task notes
 $tasknotes = "Intern: " . $document->internal_party;
 $tasknotes .= "\n";
 $tasknotes .= "Kommentar: " . $document->comment;
 $tasknotes .= "\n\n";
 $tasknotes .= $filepath;
 # Asana implementation
 require_once dirname(__FILE__) . '/php-asana-api/asana.php';
 # API key, workspace and project
 $asana = new Asana(array('apiKey' => ASANA_APIKEY));
 # workspace 'xxx'
 $workspaceId = $document->asana_workspace_id;
 # project 'xxx'
 $projectId = $document->asana_project_id;
 # create the task
 $result = $asana->createTask(array('workspace' => $workspaceId, 'name' => $taskname, 'notes' => $tasknotes, 'assignee' => $asana_owner, 'followers' => $asana_follower));
 // success is 201
 if ($asana->responseCode != '201' || is_null($result)) {
     $asana_message = 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
     $asana_error = true;
 }
 if (!$asana_error) {
     $resultJson = json_decode($result);
     # get the task id
     $taskId = $resultJson->data->id;
Exemplo n.º 11
0
 /**
  * Function retrieves upcoming IPOs by scraping data from asx pages
  * It then compares existing records against the new records and updates the DB accordingly
  */
 private function update()
 {
     /** @var Model[] $companyData */
     $modelArray = $this->scrapeData();
     $persister = new \Persister\Company($this->db);
     // fetch all existing records out of the db - Normally I would keep this in memcache or similar
     // but memcached does not want to work on this windows environ and im not going to burn any more time
     // trying to make it comply
     $existingData = $persister->getAll();
     // for each of the models
     foreach ($modelArray as $model) {
         // if the record does not exist in the old data add it
         if (!array_key_exists($model->proposedCode, $existingData)) {
             $persister->save($model);
             // OK we have a new record. throw  a task at Asana
             if (!isset($asana)) {
                 $asana = new \Asana(array('accessToken' => ASANA_TOKEN));
             }
             $asana->createTask(array('workspace' => ASANA_WORKSPACE, 'assignee' => ASANA_ASIGNEE, 'projects' => array(ASANA_PROJECT_ID), 'name' => $model->company . " ({$model->proposedCode})", 'notes' => $model->contact));
         } else {
             $oldModel = $existingData[$model->proposedCode];
             // shove comment from old model into scraped data - yeah this is a hack, but im past looking for elegant solutions
             $model->comment = $oldModel->comment;
             if ($model->hash() === $oldModel->hash()) {
                 // no change required just unset from existing records
                 unset($existingData[$model->proposedCode]);
             } else {
                 // model needs updating cos data has changed
                 $persister->update($model);
                 unset($existingData[$model->proposedCode]);
             }
         }
         $retArray[] = $model->toArray();
     }
     // anything left in existing records? nuke them because they are no longer valid
     foreach ($existingData as $oldData) {
         $persister->delete($oldData->proposedCode);
     }
     echo json_encode($retArray);
 }
<?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()) {
Exemplo n.º 13
0
<?php

// Define Asana API Key
define('ASANA_API_KEY', 'REPLACE THIS');
define('ASANA_WORKSPACE_ID', 'REPLACE THIS');
// Include Asana API Class
require_once 'asana.php';
// Initialize Asana API Class
$asana = new Asana(ASANA_API_KEY);
$graphTodo = array();
$graphDone = array();
$errors = array('message' => '', 'detail' => '');
$users = json_decode($asana->getUsers());
if (property_exists($users, 'data') && is_array($users->data)) {
    foreach ($users->data as $u) {
        $todo = 0;
        $done = 0;
        $due = 0;
        $filters = array("assignee" => $u->id, "workspace" => ASANA_WORKSPACE_ID);
        $tasks = json_decode($asana->getTasksByFilter($filters, 'completed,due_on'));
        if (property_exists($tasks, 'data') && is_array($tasks->data)) {
            foreach ($tasks->data as $t) {
                $dueDate = new DateTime($t->due_on);
                $nowDate = new DateTime('now');
                if (!$t->completed && $dueDate < $nowDate) {
                    $due++;
                }
                if ($t->completed) {
                    $done++;
                }
                if (!$t->completed && $dueDate > $nowDate) {
Exemplo n.º 14
0
}


$datetime = new DateTime(date('Y-m-d ' . TIME_CHECK_FROM, strtotime($previous . ' day')),
    new DateTimeZone(DATETIME_TIMEZONE_CURRENT));
$datetime->setTimezone(new DateTimeZone(DATETIME_TIMEZONE_ASANA));
$startTasksDate = $datetime->format('Y-m-d\TH:i:s\Z');
echo 'Start from:' . $startTasksDate . " [" . DATETIME_TIMEZONE_ASANA . "]<br>";


/**
 * Create a client using Asana API key
 */

$asana = new Asana(array(
    'apiKey' => ASANA_API_KEY
));

// Get all workspaces
$workspaces = $asana->getWorkspaces();
// As Asana API documentation says, when response is successful, we receive a 200 in response so...
if ($asana->responseCode != '200' || is_null($workspaces)) {
    echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
    return;
}
$workspacesJson = json_decode($workspaces);
foreach ($workspacesJson->data as $workspace) {
    echo '<h3>*** ' . $workspace->name . ' (id ' . $workspace->id . ')' . ' ***</h3><br />' . PHP_EOL;
    // Get all projects in the current workspace (all non-archived projects)
    $projects = $asana->getProjectsInWorkspace($workspace->id, $archived = false);
    // As Asana API documentation says, when response is successful, we receive a 200 in response so...
Exemplo n.º 15
0
<?php

require 'asana.class.php';
$project_id = $argv[1];
$access_token = getenv('ASANA_ACCESS_TOKEN');
if (empty($access_token)) {
    die("ASANA_ACCESS_TOKEN not in environment!\r\n");
}
if (empty($project_id)) {
    die("Usage: tasks.php [project_id]\r\n");
}
$a = new Asana(array('access_token' => $access_token));
$tasks = $a->get_tasks($project_id);
print_r($tasks);
<?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>';
Exemplo n.º 17
0
function getAsanaTasks($startTasksDate = 'now')
{
    global $humanTags;
    /**
     * Create a client using Asana API key
     */
    $asana = new Asana(array(
        'apiKey' => ASANA_API_KEY
    ));

    $returnData = [];
    $tasksCounter = 0;
    $projectsCounter = 0;

// Get all workspaces
    $workspaces = $asana->getWorkspaces();
// As Asana API documentation says, when response is successful, we receive a 200 in response so...
    if ($asana->responseCode != '200' || is_null($workspaces)) {
        logStatusFailure('Error while trying to connect to Asana, response code: ' . $asana->responseCode);
        return;
    }
    $workspacesJson = json_decode($workspaces);
    foreach ($workspacesJson->data as $workspace) {
//        echo '<h3>*** ' . $workspace->name . ' (id ' . $workspace->id . ')' . ' ***</h3><br />' . PHP_EOL;
        // Get all projects in the current workspace (all non-archived projects)
        $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->responseCode != '200' || is_null($projects)) {
            logStatusFailure('Error while trying to connect to Asana [get project, workspace ' . $workspace->name . '], response code: ' . $asana->responseCode);
            continue;
        }
        $projectsJson = json_decode($projects);
        foreach ($projectsJson->data as $project) {
            $rDataKey = getClientNameByProjectId($project->id);
            $returnData[$rDataKey][$project->id] = [
                'workspace' => $workspace,
                'project' => $project,
                'tasks' => [],
            ];
            // Get all tasks in the current project
            $tasks = $asana->getTasksByFilter(['project' => $project->id, 'workspace' => $workspace->id],
                ['modified_since' => $startTasksDate/*, 'opt_fields' => 'tags, name'*/]);
//        var_dump($tasks);die;

            $tasksJson = json_decode($tasks);
            if ($asana->responseCode != '200' || is_null($tasks)) {
                logStatusFailure('Error while trying to connect to Asana [get tasks, project "' . $project->name . '"], response code: ' . $asana->responseCode);
                unset($returnData[$rDataKey][$project->id]);
                continue;
            }
            $tasks = array();
            foreach ($tasksJson->data as $task) {
                $taskFullInfo = $asana->getTask($task->id);

//        var_dump($tasks);die;

                $taskJson = json_decode($taskFullInfo);
                if ($asana->responseCode != '200' || is_null($tasks)) {
                    logStatusFailure('Error while trying to connect to Asana [get task Info. Project "' . $project->name . '". Task "' . $task->name . '"], response code: ' . $asana->responseCode);
                    unset($returnData[getClientNameByProjectId($project->id)][$project->id]);
                    continue;
                }

                $lastChar = substr(trim($taskJson->data->name), -1);
                if ($lastChar != ':') {
                    $taskTags = [];
                    if ($taskJson->data->tags) {
                        foreach ($taskJson->data->tags as $taskTag) {
                            $taskTags[] = strtr($taskTag->name, $humanTags);
                        }
                    }
                    $tasks[] = array(
                        'txt_link' => 'https://app.asana.com/0/' . $project->id . '/' . $taskJson->data->id,
                        'link' => [
                            'url' => 'https://app.asana.com/0/' . $project->id . '/' . $taskJson->data->id,
                            'title' => 'https://app.asana.com/0/' . $project->id . '/' . $taskJson->data->id
                        ],
                        'task_type' => '',
                        'completed' => $taskJson->data->name,
                        'notes' => '',
                        'created_at' => $taskJson->data->created_at,
                        'modified_at' => $taskJson->data->modified_at,
                        'tags' => implode(", ", $taskTags),
                    );
                }
//                    $tasks[] = '+ <a target="_blank" href="https://app.asana.com/0/'.$project->id.'/'.$task->id.'">' . $task->name . '</a> '
//                        /*.(($task->tags) ? " [".implode (", ", $task->tags)."] " : '')*/.'<br>' . PHP_EOL;
            }
            if ($tasks) {
                $returnData[$rDataKey][$project->id]['tasks'] = $tasks;
                $tasksCounter = $tasksCounter + count($tasks);
                $projectsCounter++;
            } else {
                unset($returnData[$rDataKey][$project->id]);
            }
        }

        // remove empty entities
        if ($returnData) {
            foreach ($returnData as $clientName => $clientData) {
                if (!$clientData) {
                    unset($returnData[$clientName]);
                } else {
                    foreach ($clientData as $projectId => $projectData) {
                        if (!$projectData) {
                            unset($returnData[$clientName][$projectId]);
                        }
                    }
                }
            }
        }
    }

//    var_dump($returnData);die;

    return [
        'data' => $returnData,
        'tasksCounter' => $tasksCounter,
        'projectsCounter' => $projectsCounter,
    ];
}
Exemplo n.º 18
0
<?php

/*
 * This file is part of the Showpad PHP API connection class from Jeroen Desloovere.
 *
 * For the full copyright and license information, please view the license
 * file that was distributed with this source code.
 */
// required to load
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/credentials.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
$workspaces = $asana->getWorkspaces();
// As Asana API documentation says, when response is successful, we receive a 200 in response so...
if ($asana->responseCode != '200' || is_null($workspaces)) {
    echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
    return;
}
$workspacesJson = json_decode($workspaces);
foreach ($workspacesJson->data as $workspace) {
    echo '<h3>*** ' . $workspace->name . ' (id ' . $workspace->id . ')' . ' ***</h3><br />' . PHP_EOL;
    // Get all projects in the current workspace (all non-archived projects)
    $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->responseCode != '200' || is_null($projects)) {
        echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
        continue;
    }
<?php

require_once '../asana.php';
// See class comments and Asana API for full info
$asana = new Asana(array('apiKey' => 'XXXXXXX.XXXXXXXXXXXXXXXXXXXXXXXX'));
// Your API Key, you can get it in Asana
$taskId = 10924433056204.0;
$asana->getTask($taskId);
// 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 "Task details:" . PHP_EOL;
var_dump($asana->getData());
$asana->getTaskStories($taskId);
// 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 "Task stories(comments):" . PHP_EOL;
var_dump($asana->getData());
Exemplo n.º 20
0
<?php

ini_set("max_execution_time", 300);
require_once 'asana.php';
$asana = new Asana(array('apiKey' => 'bZN6mBeL.7cBWsHfKEMSPcNP4gmRHiIq'));
$tasks = $asana->getProjectTasks(42248342439432);
$tasksJson = json_decode($tasks);
?>

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>ASANA</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/bootstrap.css">
<style>
  body {
  padding-top: 10px;
  padding-bottom: 10px;
  }
</style>

<link rel="stylesheet" href="assets/style.css">
<script src="assets/bootstrap.js"></script>
<script src="assets/jquery.js"></script>
Exemplo n.º 21
0
$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' => '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('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.';
}
Exemplo n.º 24
0
<?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
$result = $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->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
Exemplo n.º 25
0
<?php

require "../lib/load.php";
$model = [];
$model["workspaces"] = Asana::workspaces();
if (!empty($_REQUEST['workspace'])) {
    $model["projects"] = Asana::projects($_REQUEST['workspace']);
    foreach ($model["workspaces"] as &$ws) {
        if ($ws->id == $_REQUEST['workspace']) {
            $ws->selected = true;
        }
    }
} else {
    $model['no_workspace'] = true;
}
render("projects", $model);