Hello API experts,
I am writing to ask for hints regarding an issue we’re facing in an Asana Script Action. We consistently receive a “Bad Request” (400) error when trying what should be an easy thing to do: add an option to a custom field.
Goal
I want to use a Script Action to automatically create a new option in a single-select custom field based on a task’s due date (or a custom date field if that helps).
The Issue I’m Seeing
The API call using curl works perfectly, but the equivalent action within the Script Action environment fails.
1. Successful Test via Direct API Call: This basic manual curl command using a Personal Access Token succeeds and adds the option to the field as expected.
curl --request POST
–url ‘https://app.asana.com/api/1.0/custom_fields/[your_custom_field_gid]/enum_options’
–header ‘content-type: application/json’
–header ‘authorization: Bearer [My_Personal_Access_Token]’
–data ‘{ “data”: { “name”: “Manual-API-Test”, “enabled”: true } }’
2. Failing Script Action: This code, running inside an Asana Rule, fails with a "message": "Bad Request" error. The logic and payload are intended to be identical to the successful curl command.
// This is the failing part of the script.
// All variables (task_gid, etc.) seem to be correct.
const TARGET_CUSTOM_FIELD_GID = ‘[your_custom_field_gid]’;
const dueDate = “2025-12-06”; // Example value
const newOptionData = {
data: {
name: dueDate,
enabled: true
}
};
// This specific API call fails with “Bad Request”
try {
await customFieldsApiInstance.createEnumOptionForCustomField(TARGET_CUSTOM_FIELD_GID, newOptionData);
} catch (error) {
log(JSON.stringify(error)); // Logs: { “name”: “PromiseRejected”, “message”: “Bad Request” }
}
Troubleshooting We’ve Performed
To isolate the issue, we have already verified the following:
-
Correct GIDs: The Project GID and Custom Field GID are correct.
GETrequests for both work fine. -
Correct Field Type: The target custom field is confirmed to be of type
enum. -
Sufficient Permissions: The user who created the rule is confirmed to be both Project Admin and Field Admin.
-
Field is Not Locked
My Question: What am I doing wrong, or is this an API limitation?
I am unable to determine the cause of this. Since the direct API call succeeds but the equivalent action within the Script Action fails, I’d greatly appreciate any help and hints investigating why the customFieldsApiInstance might be returning a “Bad Request” error in this context.
Probably sth obvious I am missing?