【问题标题】:How to set custom_fields that has an enum_value using a POST HTTP request?如何使用 POST HTTP 请求设置具有 enum_value 的 custom_fields?
【发布时间】:2017-03-30 21:57:32
【问题描述】:

我正在尝试在使用 POST HTTP 请求创建的任务中设置 type enum_value 的 custom_fields。

我设法设置了一个 type number 的 custom_field,但我遇到了 type enum_value

custom_fields 问题

问题:

这是我到目前为止所做的:

1- 我创建了要在体式上填充的 custom_fields,我可以设置 type number 的 custom_fields,但不能设置 type enum_value 的 custom_fields(见附图)

这是我的代码(我尝试了不同的实现来设置不正确的 custom_fields):

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

【问题讨论】:

    标签: asana asana-api


    【解决方案1】:

    看起来您输入了 enum_value 的名称而不是 id。以下是 PUT/POST 请求和响应的示例:

    # 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"
                }
              },
              "~..."
            ]
          }
        }
    

    诚然,它有点隐蔽,但如果您查看入门文档的Custom Fields section,则有一个在“访问任务上的自定义字段值”下创建自定义字段的示例。

    【讨论】:

      猜你喜欢
      • 2017-03-10
      • 1970-01-01
      • 1970-01-01
      • 2016-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多