More options to get tasks from API

Howdy Mighty “keeper of keys

(never piss the developers, they have cookies!)

I am toying with your lovely API, in particular to retrieve a list of the uncompleted tasks assigned to a user. My goal is to create a simple page from which I can print someone’s “Today” or “Upcoming” tasks without many frills.

Now, for me it easy to get to the user’s tasks, with
GET /tasks
which in php returns the compact task record.

My issue is that to limit the tasks to the “todays” and “upcomings” I have to get the full list, then read task by task to limit my list exclusively to the groups I need. I have to do this as the GET /tasks does not allow me to specify the assignee_status nor the compact record contains it.

Is there a way to use assignee_status to shortlist the list of tasks I need to query?

Thanks

Carlo

3 Likes

@Matt_Bramlage any feedback on this?

Thanks

Hi there!

You should be able to ask for more than the id and name with the “fields” parameter in the first GET request, something like this curl example:

curl --header "Authorization: Bearer $ASANA_PERSONAL_ACCESS_TOKEN" \
"https://app.asana.com/api/1.0/tasks?assignee=me&limit=100&workspace=$WORKSPACE_ID&opt_fields=name%2Cassignee_status"

With our php client library that ends up looking something like the following example:

<?php
require dirname(__FILE__) . '/vendor/autoload.php';  // This is using Composer for dependencies
use Asana\Client;
$ASANA_PERSONAL_ACCESS_TOKEN = getenv('ASANA_PERSONAL_ACCESS_TOKEN'); // Get my access token from the shell environment

$client = Asana\Client::accessToken($ASANA_PERSONAL_ACCESS_TOKEN);
$taskIterator = $client->tasks->findAll(array('workspace'=>getenv('ASANA_WORKSPACE_ID'), 'assignee'=>'me'),
  array('fields'=>array('name', 'assignee_status'), 'item_limit'=>10)
);

foreach ($taskIterator as $index => $task) {
  var_dump($task);
}
4 Likes

Fabulous, I did not understand I can as for additional fields.
Works like a charm and reduces the API calls sensibly!

Thank You @Matt_Bramlage

2 Likes