Hi,
I am trying to access tasks relating to a project, but this seems to fail on my side.
I can access the tasks by running the below
$projects = $client->get('/projects', []);
But when trying to access tasks assigned to a project as per below, I can’t seem to get a return
$arr = $client->get('/projects/' . $projects[49] . '/task', []);
I get the following error when trying to dd the $arr
Object of class stdClass could not be converted to string
Also, it would be for all users and not one user on the platform.
Try “/tasks” instead of “/task”
To get tasks from 1 users:
/users/xxx/tasks
But, you can’t get tasks of 1 users of 1 project using one of these methods. You will need to query the “search” endpoint of you need to do that without filtering results.
Hi Frederic, thank you, I will attempt to get the tasks using the search endpoint. Much appreciated
Shane8
July 26, 2022, 10:57am
4
I got individual project tasks with the following:
<?php
require 'vendor/autoload.php';
$client = Asana\Client::accessToken('INSERT ACCESS TOKEN');
$project_id = 'INSERT PROJECT ID';
$tasks = $client->tasks->getTasksForProject($project_id, [], []);
foreach($tasks as $task) {
echo $task->name . "<br>";
}
Then I got all tasks for all projects with the following:
<?php
require 'vendor/autoload.php';
$client = Asana\Client::accessToken('INSERT ACCESS TOKEN');
$workspace_gid = 'INSERT YOUR WORKSPACE ID';
$projects = $client->projects->getProjectsForWorkspace($workspace_gid);
foreach($projects as $project) {
// Get Project Info.
echo "<br>" . $project->name . ": " . $project->gid . "<br>";
$tasks = $client->tasks->getTasksForProject($project->gid, [], []);
foreach($tasks as $task) {
// Get Task Name.
echo $task->name . "<br>";
}
}
1 Like