API & getting multiple custom fields

Hey folks,

So I’m trying to use Google Sheets/Scripts to get information about all of the custom fields associated with tasks in a project in Asana. I can get the first custom field but am unable to get any of the other ones. Any help would be greatly appreciated.

function myFunction() {
var requestUrl = “https://app.asana.com/api/1.0/projects/615653281333293/tasks? opt_fields=id,assignee,assignee_status,created_at,completed,completed_at,due_on,name,custom_fields,custom_fields,custom_fields&limit=25”

 var headers = {
  "Authorization" : bearerToken

var reqParams = {
  method : "GET",
  headers : headers,
  muteHttpExceptions: true
  var response = UrlFetchApp.fetch(requestUrl, reqParams);
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheets = ss.getSheets()
  var sheet = ss.getSheetByName("99 Problems"); 

  var dataAll = JSON.parse(response.getContentText());
  var dataSet = dataAll.data;
  var rows = [],
     var i = 0;
     for (i; i < dataSet.length; i++)
       data = dataSet[i];
       rows.push([data.id, data.name, data.assignee, data.created_at, data.completed_at, data.completed,data.due_on, data.custom_fields,data.custom_fields])  

Maybe you will get luckier using the “Explorer” tab on Build an app with Asana
That could help understand how it works!

Asana Certified Pro, consultant, author and developer

Thanks for the suggestion. Sadly I can’t find any information there about getting multiple custom fields there. I’m not trying to call each task individually, rather as a group from a project. I can get the first custom field from each task just fine.

What @Bastien_Siebman was suggesting - a good idea! - is to run your request (i.e. projects/615653281333293/tasks? opt_fields=id,assignee,assignee_status,created_at,completed,completed_at,due_on,name,custom_fields,custom_fields,custom_fields although you don’t need custom_fields 3 times) in Explorer and see what you get back for custom fields.

It’s really odd that you would only get one - they come together as an array. Are you sure the other custom fields have been added to that particular project? My recollection is I believe you’ll only get back custom fields which exist in the particular project you’re querying.

1 Like

@Phil_Seeman Thanks for clarifying! I’ve been looking at the explorer and don’t see a way to get custom fields from it. Am I just missing it somewhere? I figured out how to add it to the url by trial and error. If they are coming as an array then the error might be in how I’m pushing the data to google sheets.

@Phil_Seeman Your bit about the custom fields coming as an array totally solved it. Thanks! I needed to be pushing data.custom_fields[0], data.custom_fields[1] ect.

@Bastien_Siebman Thanks for pointing me in a good direction!



I also have to get status of milestone. image . I am attaching the screen shot.
How can I get this status?

Thanks and Regards,
Ravi Shankar

See this forum thread: