Update the value/chosen option of enum custom field in a task through client.tasks.update

I have been trying to update the selected option in a custom field based on the instructions provided here but even though the API returns the task data as expected, it does not set the option in the custom field.

My custom field is named ‘Due date format’ and it has two options: ‘Dynamic’ and ‘Fixed’.
I confirmed that i successfully fetched the GID of the custom fields and its options, as well as the GID and data for the task.

I’m using this code:

print(custom_field.get(‘enum_options’)) # Got the ID of each option through this line.

Dynamic type enum_option GID: 1206558670504134, Fixed: 1206558670504135

Prepare the data payload to update the custom field

due_date_format_id = ‘1206558670504133’
dynamic_option_gid = ‘1206558670504134’
data = {
‘data’: {
‘custom_fields’: {
due_date_format_id: dynamic_option_gid # ‘gid’ of ‘Due date format’: ‘gid’ of ‘Dynamic’
}
}
}

Make the PUT request to update the task with the default enum value

response = client.tasks.update(task_GID, data)

Find the custom field in the response

custom_field_response = next(
(field for field in response[‘custom_fields’] if field[‘gid’] == due_date_format_id),
None
)

Check if the custom field was found and print relevant information

if custom_field_response:
print(f"Custom field ‘{custom_field_response[‘name’]}’ with GID {due_date_format_id} found in the response.“)
if custom_field_response[‘enum_value’]:
print(f"Value: {custom_field_response[‘enum_value’][‘name’]}”)
else:
print(“Value not set.”) # This is the final case, i.e. there’s no enum_value set after running the code.
else:
print(f"No custom field found with GID {due_date_format_id} in the response.")

My code successfully identifies the task and custom field, but the set option is not updated. Can you help identify why this is happening?

Hi @Leonardo_Ibarra ,

Welcome to the forum! Sorry, I’m having a hard time parsing your code. Are you using one of the client libraries?

To confirm, you are trying to update an enum field on an existing task, right? Generally speaking, your process would be something like:

  1. Get the gid for target task
  2. Get the gid for your enum field and the gid for any enum_options
  3. Call this endpoint with a PUT method and a body something like:
let body = {
    "data": {
        "custom_fields": {
            "field_gid": "enum_option_gid"
        }
    }
};

This is generally the same process I think you were following while still encountering errors, so a few questions:

  1. How are you confirming that the option didn’t update? In the return for the function, are you specifying custom_fields in the opts parameter?
  2. Are you passing in the key:value within a custom_fields object (I think calling GET tasks returns the fields as an array of objects)?
  3. Are you making sure that both the key and value (field and option gid) are strings and not numbers?