如何使用POST HTTP请求设置具有enum_value的custom_fields? [英] How to set custom_fields that has an enum_value using a POST HTTP request?

查看:620
本文介绍了如何使用POST HTTP请求设置具有enum_value的custom_fields?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我设法设置了一个类型编号的custom_field,但是我遇到了 type enum_value

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

问题:

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

Here's what I did so far:

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

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)

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

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

推荐答案

似乎您输入了enum_value的名称而不是id.这是一个PUT/POST请求和响应的示例:

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

这篇关于如何使用POST HTTP请求设置具有enum_value的custom_fields?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆