Api & Custom Fields


#1

Hi,
i need to update (or create) via API (curl) a task, with some custom fields (enum type) populated.
Just as an example, i have this custom field with these 4 options:
{“id”:318336795802518,“enum_options”:
[{“id”:318336795802519,“enabled”:true,“name”:“A Miss”},
{“id”:318336795802520,“enabled”:true,“name”:“A Country miss”},
{“id”:318336795802521,“enabled”:true,“name”:“A Country price anomaly”},
{“id”:318336795802522,“enabled”:true,“name”:“B Anomaly”}],“name”:“Bug Type”,“type”:“enum”},

The job id i need to update is 318401568256461, so my curl expression is:
curl --request PUT -H “Authorization: Bearer MYAPIKEY” https://app.asana.com/api/1.0/tasks/318401568256461 --data-urlencode “custom_fields:{318336795802518:318336795802520}”

I don’t get any error but the job is not updated. Do i miss something? Thanks


#2

Looping in one of Asana’s Developer Relations Leads, @Matt_Bramlage, who I’m hoping can help get your issue addressed! :slight_smile:


#3

Hi there!

Sorry for such a long delay - things have been quite active over here!

Setting custom fields with input being form data can be quite tricky. If you’re using JSON, your format is spot on:

"data": {
    "custom_fields":{
        318336795802518:318336795802520
    }
}

with form data (which is what --data-urlencode sends, setting the content type to application/x-www-form-urlencoded) you have to get the path specifier just right in order for it to work. This means a successful request would be

curl --request PUT -H "Authorization: Bearer MYAPIKEY" \
https://app.asana.com/api/1.0/tasks/3184015682564611 \
--data-urlencode "custom_fields.318336795802518=318336795802520"

Hopefully this will work for you!


#4

I’m not able to update the custom fields and get “errors”:[{“message”:"custom_fields: Value is not valid JSON:

{ 
  "id":392096801051329,
  "custom_fields":{
    "24321869754625":"Test", 
    "188798652655039":197365168746421 
  },
  "due_on":"2017-08-01",
  "name":"James",
}   

It seems to be in the format provided and If I remove the custom_fields parameter I am able to update my task. What is missing?


#5

Hello,

I would like to recover my tasks with the custom field and others information but I can’t do it.
Can you give me the URL knowing I have this one for now et I want to have theses information too.
https://app.asana.com/api/1.0/projects/557333570332796/tasks?opt_fields=name,due_on,completed,assignee,memberships.section.name&opt_pretty

Thank you !


#6

Same boat here as James_Ferreira. I can’t seem to update the custom field no matter what kind of format I try.

  var headers = {
    'Authorization': 'Bearer API_KEY'
  };
  
  var formData = "custom_fields.661393451384417=123";
  
//  var formData = {
//    'custom_fields': {661393451384417: 123},
//  };

  //formData['custom_fields'][fieldId.toString()] = value;
  var options = {
    'method': 'put',
    'headers': headers,
    'payload': formData
  };
  var response = UrlFetchApp.fetch('https://app.asana.com/api/1.0/tasks/' + taskId, options);
  Logger.log(response.getContentText());
}

What are we doing wrong?


#7

Did you ever hear back from anyone? I’m stuck in the exact same situation. Thanks!


#8

This does not work. Even on regular CURL on the terminal I get “Could not interpret 683685779381761 as an identifier in custom_fields.683685779381761”

This is the CURL request and I am trying to set an number custom field
curl --request PUT -H “Authorization: Bearer MYKEY”
https://app.asana.com/api/1.0/tasks/686202313755564
–data-urlencode “custom_fields.683685779381761=36”

Please Advise