How to set custom_fields that has an enum_value using a POST HTTP request?

房东的猫 提交于 2019-12-25 05:13:13

问题


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)

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:


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".



来源:https://stackoverflow.com/questions/43129086/how-to-set-custom-fields-that-has-an-enum-value-using-a-post-http-request

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!