Help Request: "Bad Request" Error in Script Action for createEnumOptionForCustomField

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. GET requests 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?

@Daniel_Kreiss - does the author of the script have edit permissions on the field?

Hi @Daniel_Kreiss ! The issue here is that you need to wrap the data parameter inside a body object.

Your version:

const newOptionData = {
  data: {
    name: dueDate,
    enabled: true
  }
};

Correct version:

const newOptionData = {
  body: {
    data: {
      name: dueDate,
      enabled: true
    }
  }
};

This is required because the opts field can include other parameters (like opt_fields). You can see an example of this in our API Reference, by selecting Node from the language list at the top of the page.

Hope this helps!

Best,
Dominik

5 Likes

I’m thrilled, works like a charm now! Thanks for your fast support.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.