Set task custom field using curl

I’m trying to create a script that can create tasks for me and set their custom fields.
So far I figured out that my project ID is 727740646475748.
If I call GET /projects/727740646475748, I find that my custom field ID 727729591481443 is and value ID is 727729591481447. Full json @ https://pastebin.com/XqDLst8G, I’m trying to select the “Cassandra Test” enum value.

According to this page: /developers/documentation/getting-started/custom-fields
This should work
curl --request PUT -H “Authorization: Bearer <personal_access_token>”
/api/1.0/tasks/1125479699210021
-d
‘{
“data”: {
“custom_fields”:{
“727729591481443”:“727729591481447”
}
}
}’
But I get
{“errors”:[{“message”:“Could not interpret {\n “data”: {\n “custom_fields”:{\n “727729591481443”:“727729591481447”\n }\n }\n} as an identifier in {\n “data”: {\n “custom_fields”:{\n “727729591481443”:“727729591481447”\n }\n }\n}.”,“help”:“For more information on API status codes and how to handle them, read the docs on errors: /developers/documentation/getting-started/errors”}]}

According to this page /developers/api-reference/tasks#setting_custom_field_values
This should work
curl --request PUT -H “Authorization: Bearer <personal_access_token>”
https://app.asana.com/api/1.0/tasks/1125479699210021
-d “custom_fields:{727729591481443:727729591481447}”
But I get
{“errors”:[{“message”:“Could not interpret custom_fields:{727729591481443:727729591481447} as an identifier in custom_fields:{727729591481443:727729591481447}.”,“help”:“For more information on API status codes and how to handle them, read the docs on errors: /developers/documentation/getting-started/errors”}]}

What am I doing wrong?

(can you use the editor to format your code please? thanks :+1:)

I didn’t see a format code option, so I just left it. I also can’t seem to find an edit button, can I even edit posts? I’m new here.

Indeed you can’t when you are new member :slight_smile:

Documentation says:
SETTING CUSTOM FIELD VALUES Custom fields are set with PUT requests similarly to setting other fields on tasks; the format of the request is to set the id to the new value. That is, custom_fields:{custom_field_id:custom_field_value}
but looks like you are setting custom_fields on your end…

@Floris_Thijssen Try following the syntax shown in this post:

1 Like

I tried
curl --request PUT -H "authorization: Bearer SNIP" https://app.asana.com/api/1.0/tasks/1125479699210021 --data-urlencode "custom_fields[727740646475736]=1109215504501105"
And it gave me
{"errors":[{"message":"custom_fields: Value cannot be an array: []","help":"For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors"}]}

Ah wait, I think there’s a typo in what was suggested - I think it should be custom_field singular. In other words, try:

curl --request PUT -H "authorization: Bearer SNIP" https://app.asana.com/api/1.0/tasks/1125479699210021 --data-urlencode "custom_field[727740646475736]=1109215504501105"

1 Like

curl --request PUT -H "authorization: Bearer SNIP" https://app.asana.com/api/1.0/tasks/1125479699210021 --data-urlencode "custom_fields[727740646475736]=1109215504501105"
Returns the JSON of the task, but the task itself isn’t getting changed. Output: https://pastebin.com/VTFAg1cM
I also noticed that the JSON that gets returned has different IDs than the one I use, so I tried using --data-urlencode "custom_field[727729591481443]=727729591481449"
But I’m still just getting the JSON back and the task isn’t getting changed

Arghh, just tried it myself and I get the same result - it returns the task as if it worked but the custom field value is not changed.

@Joe_Trollo @Jeff_Schneider @Matt_Bramlage @Ross_Grambo Any ideas here, guys, on what the proper syntax is to update a task’s custom field value via curl?

It works for me if I use:

curl -X PUT https://app.asana.com/api/1.0/tasks/<task-id> -H 'Authorization: Bearer <pat>' -H "Content-Type: application/json" -d '{"data":{"custom_fields":{“<custom-field-id>":"It worked!"}}}'

Does this work for you?

Not me - when I try that, I get:
"Could not parse request data, invalid JSON"

@Floris_Thijssen, how about you? Does it work for you?

I got a JSON error as well, but that’s because the first double qoute in “<custom-field-id>" isn’t a double quote. If I correct that, it just returns the JSON of the task again, but no fields are getting updated. Maybe it has something to do with the fact that my custom field is an enum instead of a string?
Also, this is starting to look more like a bug, can someone move this thread to the report-a-bug category?

oh never mind, looks like I can move it myself

Hi @Floris_Thijssen. Thank you for reaching out!

All the posts related to API Question including Bugs are handled in the #developersAPI category.

If it’s Ok with you, I’m moving this post back to #developersAPI so our team can directly assist you on this issue.

1 Like