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 @ { "data": { "id": 727740646475748, "gid": "727740646475748", " - Pastebin.com, 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”}]}
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…
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"}]}
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: { "data": { "assignee": { "gid": "695462050098932", "id": - Pastebin.com
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
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?
The issue here is a missing content type header. @Ross_Grambo was able to make a successful cURL request because he added -H "Content-Type: application/json" to the command. Without that, the API won’t correct interpret the body and you’ll see a Cannot interpret... error.
@Phil_Seeman, you likely got an invalid JSON error when running Ross’ command because he accidentally had a “smart” quote in the body of his request, which is invalid JSON. “<custom-field-id>" should be "<custom-field-id>" (note the difference in the first character).