getWorkspaces() public method

Returns all the workspaces.
public getWorkspaces ( array $opts = [] ) : string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null
<?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;
    }
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,
    ];
}