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
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
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”
Can you post some specific code that you’ve tried which hasn’t worked? I think having that as a starting point might make it easier to provide some advice.
@Matt_Bramlage Hey Matt, these guys are correct - I just tried the CURL syntax you suggested above (and a bunch of variations of it) and got the same error.
For example, given a task with a text custom field having id 744020393575926, if I do:
curl --request PUT -H "authorization: Bearer MY-PERSONAL-ACCESS-TOKEN" https://app.asana.com/api/1.0/tasks/718125926216046 --data-urlencode "custom_fields.744020393575926=A field updated from CURL"
that results in the error Could not interpret 744020393575926 as an identifier in custom_fields.744020393575926.
Dim request As HttpWebRequest = WebRequest.Create(uri1)
request.Headers.Add(String.Format("Authorization: Bearer {0}", token))
request.Method = "PUT"
request.ContentType = "application/x-www-form-urlencoded"
Dim response As HttpWebResponse = request.GetResponse()
Method2:
Dim uri As String = String.Format("tasks/{0}", taskId)
request.Headers.Add(String.Format("Authorization: Bearer {0}", token))
request.Method = "PUT"
request.ContentType = "application/json"
Dim cfParams As New Dictionary(Of String, Object)
cfParams.Add(customFieldId, value)
Dim parameters As New Dictionary(Of String, Object)
parameters.Add("custom_fields", cfParams)
Dim json As String = JsonConvert.SerializeObject(parameters)
Using writer As New StreamWriter(request.GetRequestStream())
writer.Write(json)
End Using
Dim response As HttpWebResponse = request.GetResponse()
Great thanks. That has worked I think the API reference could be clearer and provide a code example using the parameters you outlined (and maybe in a couple of different languages). Just for clarity!
How can I specify multiple custom fields in the one packet? I have tried making "custom_fields
an array but it won’t work. If custom_fields is specified more than once, the last one wins.
I can’t work out how to create a task and specify multiple custom fields in one call.
@Phil_Seeman It’s not well documented (I’ll create a follow up task to fix this) but indexing into arrays using form data is done with square brackets both for offset-based arrays (like collaborators[0], collaborators[1]) and for associative arrays (using IDs). Try:
curl --request PUT -H "authorization: Bearer MY-PERSONAL-ACCESS-TOKEN"
https://app.asana.com/api/1.0/tasks/718125926216046 --data-urlencode
"custom_fields[744020393575926]=A field updated from CURL"
This is also how you can set multiple fields at once @joehanna - by sending multiple --data-urlencode command line params with different custom fields indexed this way I was able to check that this did the right thing: