0

I want to list all tasks (and their custom fields) assigned to each user (assignee). My loop to list all users works. But, I don't success to list their tasks (and tasks' custom fields). Indeed, the answer is null...

Where I'm wrong ? How to list tasks by assignee and get each task custom fields ?

<?php
require '../vendor/autoload.php';
$me = $client->users->me();
$users = $client->users->findByWorkspace($me->workspaces[0]->id, null, array('iterator_type' => false, 'page_size' => null))->data;

foreach($users as $user){
    echo '<h2>'.$user->name.'</h2>';

    // and this doesn't work :
    $tasks = $client->tasks->findAll( ['assignee' => $user->id] );
    var_dump($tasks);
}

Thank you very much !

Alexis

Alexis
  • 21
  • 1
  • 3

1 Answers1

0

According to the Asana API Reference about querying Tasks:

You must specify a project or tag if you do not specify assignee and workspace.

That means that you require at least 2 parameters, assignee and workspace.

$taskIterator = $client->tasks->findAll(array(
    'workspace'=> {INSERT HERE THE WSPC ID}, 'assignee'=>'me')
);

You can easily iterate over all workspaces to achieve what you are aiming, for that, you can use the field workspaces that is returned from:

$client->users->me();
//or with a direct reference
$client->users->me()->workspaces;

findAll() also supports an optional array of fields:

$taskIterator = $client->tasks->findAll(array(
     'workspace'=> {INSERT HERE THE WSPC ID}, 'assignee'=>'me'),
array(
    'fields'=>array('name', 'assignee_status'), 'item_limit'=>10)
);
Nick
  • 729
  • 8
  • 18