API to GET Comments of a Task

I am using Comments field to provide status updates on Tasks. How and which API should I use to GET all or most recent the Comments of a task?

Hi @Rohit_Chowdhary,

In the Asana API, task comments are called “stories”. So you want to use the set of endpoints involving Stories:

Note, though, that there are two kinds of stories. User-generated stories are comments. System-generated stories are the notes that Asana adds to reflect changes which occur to the task. So when you’re retrieving the set of stories for a task in the API, you’ll probably want to look at the type field - it will be comment for user-generated stories and system for the latter type (which you’ll probably want to ignore in your case).

2 Likes

And what is the relationship reference between a Task and its Stories? If I have the Task Id, how do I get all or one of its Story?
Thank you for your quick response for my initial question.

If you have the task ID, get all of its stories using that ID here:

The only way to retrieve just one story would be to have its Story ID, but you likely won’t have that in the normal course of things.

2 Likes

Hi @Rohit_Chowdhary,

You can get the comments/stories on a task with the following API call Get stories from a task (GET /tasks/{task_god}/stories)

Here’s what that request looks like in cURL:

curl --location 'https://app.asana.com/api/1.0/tasks/<TASK_GID>/stories' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <YOUR_ASANA_PERSONAL_ACCESS_TOKEN>'

Since this is a GET request you could just paste this URL into your browser and see results https://app.asana.com/api/1.0/tasks/<TASK_GID>/stories (Assuming you are logged into Asana on that browser)

Note: the Get stories from a task endpoint returns a “compact records for all stories” if you are interested in more properties on the Story schema you can ask for them using the opt_fields query param.

Here’s what that request might look like in cURL

curl --location 'https://app.asana.com/api/1.0/tasks/<TASK_GID>/stories?opt_fields=created_at,created_by,target,text' \
--header 'Accept: application/json' \
--header 'Authorization: Bearer <YOUR_ASANA_PERSONAL_ACCESS_TOKEN>'

Notice how target is not in the compact stories schema

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.