无法在 Asana 中创建带标签的任务

Can't create Task with Tag in Asana

当我尝试使用下面的 JSON 创建任务时,出现此错误:

{
    "errors": [
        {
            "message": "tags: [0]: Not a valid ID type: object",
            "help": "For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors"
        }
    ]
}

我试过没有标签 属性 并且它有效。标签的预期格式与其他数组属性(成员资格、关注者等)的格式相同,所以我不确定我做错了什么。项目和标签都存在于工作区中。

JSON 请求:

{
    "data": {
        "due_on": null,
        "assignee": null,
        "workspace": 227967273629890,
        "name": "API task test2 with tag",
        "notes": "foo",
        "followers": [],
        "memberships": [{
            "project": 317773627482488,
            "section": 0
        }],
        "tags": [{
            "id": 375539822976838,
            "name": "Tag3"
        }]
    }
}

请注意,我正在序列化 C# class 并将其写入请求流。如果我不添加到 Tag 数组,它会起作用,但我不确定格式有什么问题 - 它与 Membership 和 Follower 数组相同,它们工作正常。我尝试从标签 class 中删除名称 属性,并将 id 更改为字符串中的对象 - 同样的错误:

[DataContract]
public class TaskToCreate
{
    [DataMember]
    public Data data { get; set; }
    public class Follower
    {
        [DataMember]
        public string id { get; set; }
    }
}
[DataContract]
public class Data
{
    [DataMember]
    public string due_on { get; set; }
    [DataMember]
    public string assignee { get; set; }
    [DataMember]
    public long workspace { get; set; }
    [DataMember]
    public string name { get; set; }
    [DataMember]
    public string notes { get; set; }
    [DataMember]
    public TaskToCreate.Follower[] followers { get; set; }
    [DataMember]
    public Membership[] memberships { get; set; }
    [DataMember]
    public Tag[] tags { get; set; }
}
[DataContract]
public class Membership
{
    [DataMember]
    public long project { get; set; }
    [DataMember]
    public long section { get; set; }
}
[DataContract]
 public class Tag
 {
    [DataMember]
    public object id { get; set; }
 }

读取响应和写入数据在 Asana API 中不是均匀对称的。要创建带有标签的任务,您只需提供一组标签 ID。如果您 GET 一个任务,响应将包含标签作为键值对数组。

要修复您的数据,您需要将标签数组更改为仅包含标签 ID。下面是创建带有两个标签的任务的示例请求:

curl --request POST -H 'Content-Type: application/json' -H "Authorization: Bearer 0/abc123456789" \
https://app.asana.com/api/1.0/tasks \
    -d 
    '{
        "data": {
            "projects": "123456789",
            "name" : "I'm a task from curl",
            "tags": ["123456789", "234567890"]
        }
    }'