+ Add Question

Use API to auto-add/inherit labels?

I've started moving all my Nirvana tasks over to Todoist now, and there's a lot, especially when you do it manually one by one. So I have avoided my tags (labels) for now, since that's so much extra work to add. I don't know yet if I'm able to keep my Todoist organized enough, since "Today" view is going to be a big mess of "work" and "personal" projects, and I don't want to manually add the same label over and over again to all my work tasks.

So I was wondering, do you guys think it's possible to use the API (http://todoist.com/API/help/sync) to auto-add labels?

I imagine writing a service that, few times a day, finds my "WORK"-project, then lists all the tasks in it and if some of them don't have a "@work"-label, then add it through the API. I think this will allow me to more easily only search for @work related tasks while hiding all the personal stuff.

Any thoughts? Or will Todoist release an update soon that allows us to add labels to projects and an option for new tasks to inherit those labels?

All responses

David Trey  staff
Replied on Feb 13, 2014 - 15:57 UTC

Hello Klaus,

We may add an option to filter search results by project, though we can't give you any ETA when.

I will pass your question to the developers and will let you know when they answer.

Best regards,

Klaus Thuesen  premium
Replied on Feb 13, 2014 - 19:07 UTC

Thanks David.

And if anybody has worked with Todoist API before and know the answer to my question, they are welcome to answer as well :)

Klaus Thuesen  premium
Replied on Feb 21, 2014 - 15:47 UTC

It got too annoying to have my personal and work stuff mixed together in "Today" view, and manually adding every single work-related task with "@work"-label would be a waste of time. So I went ahead with the API, and my prototype seems to work. Not using the sync API though, but this one: http://todoist.com/API/help/standard

Basically it goes like this (for anybody who needs the same functionality as I do):

First I create the label that I want to auto-add, and then I use "API/getLabels" to get the ID for the label, the first time, then hardcode label ID it into my script, as well as the name of the project I want to auto-add labels for, this is like a "super project" that holds all my work-related projects, so the project is called "@WORK" (project name, same name I use for my label).

Then I use "API/getProjects" to loop through all my projects until it finds "@WORK" (which is actually the 2nd one it finds, "Inbox" is first), it holds the "indent" value of that project, continues looping and adding project ID's to an array, until it reaches a project with same indent as "@WORK" project, which means there are no more projects under super project "@WORK". Luckily, the API returns the projects in the correct order, as shown in Todoist Web, so this works well. Otherwise the "item_order" could probably have been used to do a manual sorting first.

Now that we have an array of project ID's, I use "API/getUncompletedItems" to find all uncompleted items for the project ID's from the array. Each item holds an array of "labels" (ID's), so I search the "labels" array to see if it already has the ID of the label that I want to auto-add. If it does not, I use "API/updateItem" to send item ID and labels (as json encoded array) to Todoist API, and the task is now updated with my label. Remember to re-send existing label ID's, so you don't remove existing labels and only add the new label.

I didn't time how long it takes to update, but it seems to spend less than a second per item. Once all items are updated, it seems to take about a quarter of a second per item to check if it has the label already.

I imagine I will just configure my webserver to run the script once a night, so it will auto-add my "work" label to all tasks I added during the day, so it's ready for my personalized Today view the following day, where I use this search query (for now): overdue @work, today @work

Jourdan Rystrom
Replied on Apr 26, 2014 - 20:29 UTC

Wow, that's great! Any more integrations you've come up with? :-)

Josh Dingus
Replied on Jul 09, 2014 - 11:21 UTC

Would be really curious to see your script and know if your still using this system?

C  premium
Replied on Jul 09, 2014 - 14:10 UTC

I'd be interested in your script, too, if you don't mind to share it?

I'm thinking about writing a similar script to work around the shortcomings of not being able to filter projects ( http://todoist.com/Support/show/20072/ ). Given up hope that will ever be fixed. So basically the idea is to add the project name as a tag, then it can be filtered.

Trish Putnam
Replied on Jul 09, 2014 - 18:59 UTC

I'm very interested in seeing this script, as well.