Problems with subtasks endpoint

Hi, I’m trying to use Asana’s API to work with the subtasks.

In the UI, I can see that we can work with custom fields, and API documentation also includes “custom_fields” in the examples. But I’ve tried to get subtask’s custom_fields, and it didn’t work.

Also, in the UI, I can see that subtasks include stories about history. But in the documentation, I didn’t find anything about subtasks stories. Also, The API doesn’t return that field in the response.

Could you help me to understand those cases?

Thanks,
Nairi

Hi,

I think I’ve read somewhere that you can’t ask for custom_fields as a whole anymore, you need to ask for example for custom_field.gid or any other field you need.

Regarding stories, a subtask is a regular task so you should be able to query them just like you would with tasks.

1 Like

No, you can still ask for opt_fields=custom_fields.

The answer is a bit complicated… First, you have to remember three things:

  1. Custom fields are associated with a project (in the API, this is represented by custom_field_settings).
  2. There are two types of custom fields: global (in your organization’s Custom Fields Library) and project-specific.
  3. By default subtasks aren’t attached to their parent task’s project, and in that state, the subtask has no custom fields associated with it; it just inherits whatever custom fields its parent is associated with.

Now let’s take an example. Say the top-level task you’re querying is named My Top-Level Task and it’s in Project A. Also say that Project A has two custom fields associated with it, Custom Field 1 and Custom Field 2.

Custom Field 1 is a global custom field. Custom Field 2 is a project-specific custom field only in Project A.

You create a subtask underneath My Top–Level Task; let’s call it My Subtask. You give My Subtask a value in both Custom Field 1 and Custom Field 2.

Now… If you keep My Top-Level Task in Project A and run your tasks/{task_gid}/subtasks?opt_fields=custom_fields query, you’ll see both Custom Field 1 and Custom Field 2 in the data for My Subtask, because its parent task is in a project which has both of those fields associated with it. You can also see this reflected in the Asana web UI, where if you look at the detail pane for My Subtask you’ll see it refers to those custom fields as “inherited fields”.

Now remove My Top-Level Task from Project A, such that it’s no longer in any project at all. Re-run your query. For My Subtask in the results, you should only see data for Custom Field 1, but NOT for Custom Field 2. (And in the detail pane for My Subtask in the web UI, in the “inherited fields” area you will see it only shows Custom Field 1.)

You no longer see the data for Custom Field 2 because (a) that custom field is specific to Project A and (b) My Subtask’s parent task is no longer in Project A so it’s no longer associated with Custom Field 2 - which means that, per my point #3 above, My Subtask has no inherited association with Custom Field 2 and thus it won’t show for that subtask.

I’m 96.5% sure that what you’re experiencing can be explained by the above info. See if that’s true.

Stories are a different object; you can’t get them in task-based queries. To get the stories for a task (or for a subtask; as Bastien says, in this case a subtask is identical to a task for getting its stories), you’ll need to do another API call using a Stories endpoint.

4 Likes

Hi Phil, thank you for the information.

Could you check this specific case with me?

Here I have a project-level task. Which has a custom field and a subtask.

And this is the subtask view. As we can see, the custom field is inherited.

But that custom field isn’t returned by the API. Overall “custom_field” field is missing from the API response. I can verify that I was able to get the stories, and the changes about custom fields are visible inside the stories.

@user4,

image

You’re on the Free version of Asana which does not support custom fields; I assume that’s the issue here.

2 Likes

Thank you for the information. For the Pro trial, it worked well.

Do you know why stories don’t include enum_custom_field_changed events?

I try to add/change custom field values, but there are no any events for those actions.

I haven’t worked with stories myself, but from the information I have, I don’t think there’s an enum_custom_field_changed event; I believe this is what you see for that scenario:

// Enum custom field changed
"change": {
  "field": "custom_fields",
  "action": "changed",
  "new_value": {
    "gid": "590432",
    "resource_type": "custom_field",
    "resource_subtype": "enum",
    "enum_value": {
      "gid": "5893024",
      "resource_type": "enum_option"
    },
  }
}

Thank you for your answer. Which object should include this object, custom_field object itself?

Phil if you check my first screenshots you will see an ‘enum_custom_field_changed’ event in stories. But it’s another account project.

Wow, look at that - sure enough, there is one!

I don’t know why you wouldn’t see it in your other workspace. Are you a guest in that workspace; that might explain it?

I use a new Asana Sandbox Developer account. I’m not sure if it’s related.

This seems odd to me.

How can we verify that this is not an API issue?

Thanks,
Nairi

@AndrewWong can you help here?

I’ve verified that this event becomes visible after some time when the custom field is changed.

Thank you,

1 Like

No need for furthermore investigations :slight_smile: