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

时间:2017-07-16 01:45:51

标签: asana-api

当我尝试使用下面的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#类并将其写入请求流。如果我没有添加到Tag数组,它可以工作,但我不确定格式有什么问题 - 它与Membership和Follower数组相同,它们工作正常。我尝试从Tag类中删除name属性,并将id从string更改为object - 同样的错误:

[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; }
 }

1 个答案:

答案 0 :(得分:1)

在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"]
        }
    }'