如何使用POST HTTP请求设置具有enum_value的custom_fields?

时间:2017-03-30 21:57:32

标签: asana asana-api

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

我设法设置了类型编号的custom_field,但我遇到类型enum_value custom_fields 问题

问题:

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

1-我创建了我想在体式上填充的custom_fields,我可以设置类型编号的custom_fields,但不能设置类型enum_value 的custom_fields(参见附图)

enter image description here

这是我的代码(我尝试了不同的实现来设置不正确的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" 
      }
    }

1 个答案:

答案 0 :(得分:0)

看起来你输入了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,则可以在“在任务上访问自定义字段值”下创建自定义字段。

相关问题