Asana::getProjectsInWorkspace PHP Method

getProjectsInWorkspace() public method

Returns the projects in provided workspace containing archived ones or not.
public getProjectsInWorkspace ( string $workspaceId, boolean $archived = false, array $opts = [] ) : string
$workspaceId string
$archived boolean Return archived projects or not
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null
    public function getProjectsInWorkspace($workspaceId, $archived = false, array $opts = array())
    {
        $archived = $archived ? 'true' : 'false';
        $options = http_build_query($opts);
        return $this->askAsana($this->projectsUrl . '?archived=' . $archived . '&workspace=' . $workspaceId . '&' . $options);
    }

Usage Example

Example #1
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;
All Usage Examples Of Asana::getProjectsInWorkspace