How to set custom_fields that has an enum_value us

2019-09-18 09:24发布

I'm trying to set a custom_fields of type enum_value in a task that I'm creating with a POST HTTP request.

I managed to set a custom_field of type number but I'm having issue with the custom_fields of type enum_value

Questions:

Here's what I did so far:

1- I created the custom_fields that I want to populate on asana, I can set custom_fields of type number but not the ones of type enum_value( see picture attached)

enter image description here

Here's my code (I tried different implementations to set the custom_fields that were incorrect) :

  var task = {
      data: {
        assignee: "me",
        workspace: "1234567", 
        projects: "9876543",
        parent: null,
        custom_fields: {
          "1234567898": 333,  // this works
          "98765": "Public" // this custom field holds an enum_values, this implementation doesn't work
        },
        notes: "Test notes" 
      }
    }

1条回答
▲ chillily
2楼-- · 2019-09-18 10:05

It looks like you put the name of the enum_value instead of the id. Here is an example of a PUT/POST request and response:

# Request
curl --request PUT -H "Authorization: Bearer <personal_access_token>" \
https://app.asana.com/api/1.0/tasks/1001 \

    -d
    '{
      "data": {
        "custom_fields":{
          "124578":"439"
        }
      }
    }'

    # Response
    {
      "data": {
        "id": 1001,
        "name": "Hello, world!",
        "completed": false,
        "...": "...",
        "custom_fields": [
          {
            "id": 124578,
            "name": "Priority",
            "type": "enum",
            "enum_value": {
              "id": 439,
              "name": "High",
              "enabled": true,
              "color": "red"
            }
          },
          "~..."
        ]
      }
    }

It's admittedly a bit buried, but if you look in the Custom Fields section of the getting started documentation, there is an example of creating custom fields under "Accessing Custom Field values on Tasks".

查看更多
登录 后发表回答