What API Endpoint to Use to See the "Selected" Option on a Custom Field for a Task

Hi!

I’m trying to figure out the API endpoint structure to get the “selected” or “chosen” custom field option among a list of options. I’ve made a request, and been able to see the whole list of options on a custom field, but it doesn’t show which one is actually selected.

For example, let’s say we have a custom field called “Location” with 3 options (city, country, beach). Let’s also say the option “city” is selected. How could I make an api call on a task to see that for the custom field “Location”, the “City” option is currently selected? Thanks in advance for any help!

31%20PM

Hi @John-Paul_Cody, It’s GET /tasks/:task and look at custom_fields[n].enum_value.name.

Larry

2 Likes

That worked, thank you! I did have a follow up question that’s related. Do you happen to know if it’s possible to see this same information with a get request at the project level. For example, I have 100 tasks in 1 project, and don’t want to have to make 100 api calls for each individual task to see its custom field data. Is it possible to make 1 project api get request, and see this task specific data in that object? Thanks again for your help!

Build an app with Asana returns compact task records only.

Build an app with Asana may be of help.

And also Build an app with Asana.

Larry

Yes you can, use /projects/xxx/tasks?opt_fields=custom_fields,other-fields,…

This is my url of custom fields:
https://app.asana.com/api/1.0/projects/project_gid/tasks?opt_fields=gid,resource_type,resource_subtype,assignee.name,assignee_status,name,due_on,memberships.section.name,custom_fields&opt_pretty
There are lot of custom fields inside it. I need to fetch status.
I am using your approach to get the status but could not get that. I also attaching the response output.
Thanks!
Regards,
Ravi

@Ravi_Shankar, It looks like the response output didn’t get included. @Phil_Seeman is the API debug master so I think if he’s willing, he’ll be your best source for troubleshooting this.

Larry

Response.pdf (210.5 KB) Apologies! Please find the response for 1 project. I have to get these following fields for each task row: Task GID,Assignee Name,Assignee Status,Due On,Section Name,Task Name,resource_type,resource_subtype,Status(custom field).
I am able to get all the fields except Status. Please help.

Thanks and Regards,
Ravi Shankar

Hi @Ravi_Shankar,

The info on the Status custom field is included in your response data.

As a tip, I recommend copying your response data and pasting it into a JSON formatter; I use:

The advantage of doing that is it lets you expand and contract various pieces of your JSON response, making it a lot easier IMO to visualize the JSON structure.

Let’s take the first task, a milestone named OSD; here’s the part of it that’s the Status custom field:

 {
 "gid" : "1148626711501449",
 "enabled" : true,
 "enum_options" : [ {
 "gid" : "1151220067203645",
 "color" : "aqua",
 "enabled" : true,
 "name" : "Submitted",
 "resource_type" : "enum_option"
 }, {
 "gid" : "1148626711501451",
 "color" : "yellow",
 "enabled" : true,
 "name" : "Art changes Needed",
 "resource_type" : "enum_option"
 }, {
 "gid" : "1148626711501450",
 "color" : "green",
 "enabled" : true,
 "name" : "Approved",
 "resource_type" : "enum_option"
 }, {
 "gid" : "1148626711501452",
 "color" : "red",
 "enabled" : true,
 "name" : "Not Approved",
 "resource_type" : "enum_option"
 }, {
 "gid" : "1184612064477469",
 "color" : "orange",
 "enabled" : true,
 "name" : "In Production",
 "resource_type" : "enum_option"
 }, {
 "gid" : "1184612224035701",
 "color" : "yellow-orange",
 "enabled" : true,
 "name" : "Art w/Licensor",
 "resource_type" : "enum_option"
 }, {
 "gid" : "1184612294622703",
 "color" : "yellow-green",
 "enabled" : true,
 "name" : "Internal Design changes needed",
 "resource_type" : "enum_option"
 } ],
 "enum_value" : {
 "gid" : "1148626711501450",
 "color" : "green",
 "enabled" : true,
 "name" : "Approved",
 "resource_type" : "enum_option"
 },
 "name" : "Status",
 "resource_subtype" : "enum",
 "resource_type" : "custom_field",
 "type" : "enum"
 }

You can see that it has 7 possible enum options, and that for this task, it’s set to the “Approved” option.

1 Like

Hi,

Thank you very much! It worked very well.

Regards,
Ravi Shankar

1 Like

Hi,
I was following this thread and I got pretty much most of it, but my call is not working as expected.
What I understood is that custom_fields come as arrays, so let’s say I want the first one of my custom fields I have to use custom_fields[1].enum_value.name

I did it, but it’s not working.
This is a section of my JSON that I slightly modified for privacy reasons

     "gid":"1199598179279534",
     "assignee":{
        "gid":"1140123822819447",
        "resource_type":"user"
     },
     "completed_at":null,
     "created_at":"2021-01-17T18:22:42.423Z",
     **"custom_fields"**:[
        {
           "gid":"1199597717454706",
           "enabled":true,
           "name":"Actual words",
           "number_value":null,
           "precision":0,
           "created_by":{
              "gid":"1199584947573930",
              "name":"XXX",
              "resource_type":"user"
           },
           "resource_subtype":"number",
           "resource_type":"custom_field",
           "type":"number"
        },
        {
           "gid":"1199595541698569",
           "enabled":true,
           "name":"Words required",
           **"number_value":**I WANT THIS**,**
           "precision":0,
           "created_by":{
              "gid":"1199584947573930",
              "name":"XXX",
              "resource_type":"user"
           },
           "resource_subtype":"number",
           "resource_type":"custom_field",
           "type":"number"
        },
        {
           "gid":"1199594765947252",
           "enabled":true,
           "enum_options":[
              {
             **ALL OPTIONS**
           ],
           "enum_value":{
              "gid":"1199594766288004",
              "color":"yellow-orange",
              "enabled":true,
              "name":"**I WANT THIS**",
              "resource_type":"enum_option"
           },
           "name":"Cliente",
           "created_by":{
              "gid":"1199584947573930",
              "name":"XXX",
              "resource_type":"user"
           },
           "resource_subtype":"enum",
           "resource_type":"custom_field",
           "type":"enum"
        }> Blockquote

this is my call:
https://app.asana.com/api/1.0/projects/MY_PROJECT_ID/tasks?opt_fields=name,completed_at,name,assignee,due_on,notes,tags,custom_fields[2].number_value,custom_fields[3].enum_value.name

Can you please point me to the mistake?
Thank you!
Nina

Hi @Nina_Virtuoso and welcome to the forum,

I’m not sure what you mean by “not working” but I would eliminate trying to get specific array elements within custom_fields and just get the whole array by using

?opt_fields=name,completed_at,name,assignee,due_on,notes,tags,custom_fields

Hi Phil, thank you for your reply.
With “not working” I mean that the call returns all required fields except the selected custom_fields. See the screenshot

I tried your call before and it works but returns lots of unnecessary fields. I was trying to “declutter” the results. Anyway, if this is the only way I’ll query the results in google sheets.

Thank you!
Nina

Honestly I haven’t tried this type of syntax but the problem with trying to get specific fields using their array element number is that there’s no guarantee of which number gets you the field you want, and even if you do figure it out, that number could change over time if you add or remove custom fields. So it’s an unreliable approach; the only guaranteed approach is to get all custom fields and deal with finding the data you want on your end, as you’re doing now.