I’m having some trouble figuring out how to use the API for Todoist. I’d like to get all the tasks with a label (or even all the tasks from a specific project with a specific label). The following code grabs all tasks, not just those with the label.
let to = Todoist.create();
let weekly = to.getTasks(
{
"label_id":"2158923611" //got this with getLabels, have also tried the name of the label here
});
console.log(JSON.stringify(weekly))
I wonder if anyone else could test this. I can get tasks with some filters but not others.
The follow code works as expected–it prints the task names to the console.
let to = Todoist.create();
let weekly = to.getTasks(
{
"filter":"today"
});
for (p of weekly){
console.log(p.content)
}
However, if I switch “today” with “@week” I get “undefined”, even though I have several tasks with that label
let to = Todoist.create();
let dir = to.getLabels();
let weekly = to.getTasks(
{
"filter":"@week"
});
for (p of weekly){
console.log(p.content)
}
In the Todoist app, I can create a filter with “@week” as the content and it works as expected. Maybe something wrong with their API or the Drafts implementation? Filtering for projects returns similar errors.
This would appear to be a bug in their API. Drafts moved to using v2 of their REST API, because they are discontinuing v1…but this doesn’t seem right. I don’t have time to dig further right now, but if you force Drafts to dropback to the v1 API, it works - and the docs between APIs do not suggest there should be and difference.
To do that, add to.apiVersion = "1" after you create the to object, but before you make any calls.