API create custom field in a project and not on workspace level

Hi there,

I’m doing the create a custom field API call with this payload

{
  "data": {
    "enum_options": [
      {
        "resource_type": "enum_option",
        "color": "green",
        "enabled": true,
        "name": "Option 1"
      },
      {
        "resource_type": "enum_option",
        "color": "red",
        "enabled": true,
        "name": "Option 2"
      }
    ],
    "is_global_to_workspace": false,
    "name": "custom field 1",
    "resource_subtype": "enum",
    "workspace": "123123123"
  }
}

I’m getting

You may not create a custom field with is_global_to_workspace set to false unless it has a custom field setting on it

Probably like others I’m confused between the difference of a “custom field” and a “custom field setting”.

Do I need to include the body once more under the “custom_field_settings” attribute? Or do I need to call add a custom field to a project directly without creating the field first? (and if so, with which body as this last call assumes that I pass a field ID)

Greetings,
PJ

I haven’t tried it myself but I think this :arrow_up: is the answer for how to create a project-specific custom field, based on this forum post:

1 Like

Hi Phil,

#success!

for others wanting an explicit working example

curl --location --request POST 'https://app.asana.com/api/1.0/projects/123123/addCustomFieldSetting?opt_pretty=<boolean>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer  xxxxxxxxxxxxx' \
--data-raw '{
    "data": {
        "custom_field": {
            "name": "hello",
            "resource_subtype": "text"
        },
    "is_important": true
    }
}'
3 Likes

Excellent! And thanks for posting that working code!

1 Like