Developer Question On Creating Tasks With Tags


#1

In the process of adding Tags to Sendana @EricLegault has a question for @Matt_Bramlage or anyone else that can help. I have clipped his question:


#4

He is trying to add tags and create a task at the same time isn’t he? Not sure it is possible, wondering if he might not have to add tags afterwards…


#5

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

#6

You can add tags on task creation, but you can’t update tags with a PUT to a task. There are specific endpoints (addTag and removeTag) to add/remove tags from existing tasks.


#7

As I said in StackOverflow: yes, it was incorrect serialization. I switched from an array of tag objects with an id property, to an array of strings and it works. Thanks Jeff!


#8

Just used this thread because I was stuck, thanks a lot! @Jeff_Schneider why don’t you document the fact that we can attach tags to a task at creation in the API documentation? :thinking:


#9

@Bastien_Siebman
In my Outlook Add-in Sendana we can add new tags and pick existing tags easily. Too bad you don’t use Outlook for Windows. I use Gmail as my provider synced to Outlook but I could never leave when I look at what Sendana does.:grinning:


#10

@Bastien_Siebman Sorry to hear you were stuck. It actually is documented under /tasks, but it could be made more clear and be in the /tags section of the docs. Thanks for the feedback on this and let us know if anything else is missing or unclear.


#11

This is indeed very clear, I must have been tired yesterday! Sorry :+1: