Dumb question(s) about php-asana usage (how do I pull a given task_gid's comments?)

So, up front, I apologize for what are probably some extremely stupid questions I am about to ask. I am not a developer, but I do muddle around with PHP scripts from time to time.

I have been using the php-asana library for a few years now for the purpose of creating new tasks. Works great for that, fairly straightforward. Recently, due to some changes in workflow at my company, I now need to pull the comments from tasks to read and do some match-up with offline data, from which I can determine if they are done or not.

The part I can not for the life of me figure out, is how to use php-asana to pull the comments for a task. I would think this would be a pretty straightforward deal: something like $c = $client->comments->getAllComments(task_gid); and then when done, the comments for that task GID would all be in $c as either an array or an object, and I could do whatever I wanted with them from there. However, I cannot for the life of me find/figure out what method would get me anything resembling that kind of functionatlity.

Anyway - if someone could help me out, it would be much appreciated.


Hi @Adam_Lambert!

Task comments in Asana are a part of the object known technically as Stories.


Stories will include not only user comments but also the updates you see in a task’s activity stream; so once you get a task’s stories, you’ll need to pick out the comments for your processing.

In terms of PHP:

I apparently need more detailed instructions. I have already been round and round with both findByTask and getStoriesForTask, and have made zero headway.

findBytask errors out (PHP Fatal error: Uncaught Error: Call to undefined method Asana\Resources\Tasks::findByTask())

getStoriesForTask returns an object that does not have any comments/events/etc in it that I can tell from a print_r() of the object.

It does seem to contain some kind of recursive objects, but I have no idea how/what to do with those in order to extract the data I want.

Do you by chance have a working example of PHP code that would get me in the ballpark?


Sorry, I’m not a PHP developer.

@Bastien_Siebman perhaps?

I was a PHP developer a long time ago but never used the Asana client. For the nodeJS, what I do often is go and read the source code of the client, it does give away a lot of info.

For example Call to undefined method might lead me to believe the method might have a slightly different name. And for getStoriesForTask I would look at the typing in the source code…

Sorry I couldn’t help more, good luck Adam you are almost there!

Thanks for the feedback.

The source code comment " * @deprecated replace with getStoriesForTask regarding the findByTask method, leads me to believe that I should be using getStoriesForTask anyway. So I’m not overly worried about trying to make findByTask work.

The getStoriesForTask method seems to work, at least it throws no errors, but the complete lack of documentation or examples on how to use it to extract Stories, when I this is one of the top-3 things a person might want to do with the php-asana library, is frustrating to say the least.

I have struggled myself with some part of the nodeJS library indeed, but eventually got it to work. What object is returned by the getStoriesForTask call?

At this point, I’ve given up on php-asana and am writing my own library using raw curl calls to the Asana API within PHP using system_exec(). I have most of what i want working already, with the exception of figuring out how I can send raw JSON to Stories without the API endpoint trying to parse the JSON within the JSON.

1 Like

I have recently gotten into Asana myself and faced the same issue of needing to get the task comments as well.

I see @Bastien_Siebman pointed me in the right direction with the reference to the getStoriesForTask call. I know you have currently used a different solution and im no developer my self but here is my solution as it might help someone else along the line.

require 'vendor/autoload.php';

$client = Asana\Client::accessToken('PERSONAL_ACCESS_TOKEN');
$task_gid = 'XXXXXXXXXXXXXXXX'; // Task id you want to pull the comments from

$comments = $client->stories->getStoriesForTask($task_gid);
foreach($comments as $comment) {

	echo $comment->text; // echo all comments
	echo '<br>';
1 Like