error while try to iterate Asana\Iterator\ItemIterator object

I use the Asana PHP package:

$results = $client->tasks->getTasks();

When I try to iterate over iterator that I get:

foreach($results as $result)
{
dd($result);
}

I got an error:

Asana\Errors\InvalidRequestError
Invalid Request
vendor/asana/asana/src/Asana/Errors/AsanaError.php:28

Can you help please?

Hi @anon98495436,

I don’t know PHP, but can you see the details of the InvalidRequestError? That might tell you the specific reasons.

If you get the error at getTask(), please check if you have specified the container of the task, such as project, tag, or a pair of workspace and assignee.

Thanks @ShunS , II handle this issue. But I have another I will create a new tread.

There is not much information with regards to this post so not 100% sure what you trying to achieve.

getTask() returns information for an individual task, here is an example to access that specific data for the required task.

<?php
require 'vendor/autoload.php';

$client = Asana\Client::accessToken('INSERT ACCESS TOKEN HERE', 
    array('headers' => array('asana-enable' => 'new_user_task_lists')));  // Asana Deprecation

$task_gid = 'XXXXXXXXXXXXXXXX'; insert task id

$tasks = $client->tasks->getTask($task_gid);

// Examples
echo $tasks->name . '<br>';
echo $tasks->notes . '<br>';
echo $tasks->assignee->name . '<br>';
echo $tasks->assignee->gid . '<br>';
echo $tasks->workspace->gid . '<br>';

I do see you are using getTasks() so it seems you trying to get information for all tasks under a project. Here is what I did to get all tasks under a project.

<?php
require 'vendor/autoload.php';

$client = Asana\Client::accessToken(''INSERT ACCESS TOKEN HERE');

$project_id = 'XXXXXXXXXXXXXXX'; // Insert project Id you want to pull tasks from

$tasks = $client->tasks->getTasksForProject($project_id);

foreach($tasks as $task) {
	echo $task->name . ": " .  $task->gid . "<br>";
}
1 Like

I have gone through the Asana documentation with regards to getTasks() and see it allows you to add filters. This is probably the reason you want to use it this way. Here is my example using getTasks()

<?php
require 'vendor/autoload.php';

$client = Asana\Client::accessToken('INSERT ACCESS TOKEN HERE');

$getTasks = [
	// Below are the filters, only use 1. For more filters go to https://developers.asana.com/docs/get-multiple-tasks
	//'project'    => 'xxxxxxxxxxxxxxx' // Insert your project ID
	//'section' => 'xxxxxxxxxxxxxxx' // Or insert your section ID
];

$tasks = $client->tasks->getTasks($getTasks);

foreach($tasks as $task){
	echo $task->name . ": " .  $task->gid . "<br>";
}

Please remember to use one filter at a time as it will push out an error unless you using a filter such as the workspace filter then you must also specify the assignee to filter on. More on this in Asana’s documentation

1 Like