Search code examples
asana

Asana get tasks api not returning recently closed tasks


With asana api i just want to get list of tasks completed in the last last 5 minutes. For that did below php code. I'm getting list of tasks that are not even closed.

//unix time before 5 minutes
$lastHour = time() - 5 * 60;

//convert to tz format
$last_run = date("Y-m-d\TH:i:s.000\Z", $lastHour);


$args =  array('completed_since' => $last_run);
$tasks = $asana->getProjectTasks($project->id, $args);

echo "<pre>"; print_r($tasks );
$tasksJson = json_decode($tasks);

Is there anything wrong in the query?


Solution

  • From the docs:

    Only return tasks that are either incomplete, or completed since the given time.

    So completed_since always returns all incomplete tasks. Originally, this was done to model the behavior in the application: you typically saw "recently completed and all incomplete" tasks in one view. The application no longer does this, but the API still follows this convention because we can't change it and break existing clients. (Also, this is used to fetch all incomplete tasks with ?completed_since=now).

    If you only want the completed tasks you can make the request you're currently using, and then filter out the ones where completed is true in PHP. It's not ideal, but I hope that clears things up!

    (BTW we are working on a new, more intuitive and expressive filtering system for the API, but it's still early in the design phase and won't be shipping. So, I wouldn't hold my breath, but we are aware that this situation needs fixing ;-))