1

When I try to create a task using the JSON below, I get this error:

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

I tried without the tags property and it works. The expected format for Tags is the same as for other array properties (Memberships, Followers, etc.) so I'm not sure what I'm doing wrong. The project and tag both exist in the workspace.

JSON request:

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

Note that I'm serializing a C# class and writing that to the request stream. It works if I don't add to the Tag array, but I'm not sure what's wrong with the format - it's the same as the Membership and Follower arrays, which work fine. I tried removing the name property from the Tag class, and changed id to object from string - same error:

[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; }
 }
Eric Legault
  • 5,706
  • 2
  • 22
  • 38

1 Answers1

1

Read responses and write data are not uniformly symmetrical in the Asana API. To create a task with tags, you only need to supply an array of tag IDs. If you GET a task, the response will include tags as an array of key value pairs.

To fix your data, you need to change your tags array to only include tag IDs. Here's an example request to create a task with two tags:

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"]
        }
    }'
Jeff
  • 456
  • 2
  • 5
  • I'd provide a Fiddler request - but I can't seem to compose one properly. I can replicate the issue in Postman, but I can't share those requests. I've also edited my question to clarify the serialization approach I'm using - which is probably the problem. – Eric Legault Jul 19 '17 at 20:59
  • Did you try changing tags to an array of tag IDs? I think that is your issue. – Jeff Jul 19 '17 at 21:05
  • Yup, solved - string array is the resolution. Thanks Jeff! – Eric Legault Jul 19 '17 at 21:09