No, you can still ask for opt_fields=custom_fields
.
The answer is a bit complicated… First, you have to remember three things:
- Custom fields are associated with a project (in the API, this is represented by
custom_field_settings
).
- There are two types of custom fields: global (in your organization’s Custom Fields Library) and project-specific.
- 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.