I used to be a Things3 user and have recently moved to Todoist and am trying to replicate the same Draft Actions I was using in Todoist.
This is my attempt at parsing out Markdown tasks into Todoist but for some reason I can’t work out how to add tags/labels to the tasks as my implementation doesn’t seem to work. I would be eternally grateful if someone could help me out with this
var content = editor.getText();
var check = content.length;
var taskList = "";
if (content.length == 0) {
alert("Draft is blank");
context.cancel("Draft was blank");
}
// Call API for each line in a draft
// split draft and loop over lines
var lines = content.split("\n");
/* --- Todoist ---*/
let todoist = Todoist.create();
for (var line of lines) {
if (line.includes("- [ ]")) {
// Todoist Action
var task = line.replace("- [ ]","");
task.labels = "meetingTask🎙";
task = task.trim();
var credential = Credential.create("Todoist", "Todoist API");
credential.addTextField("token", "Token");
credential.authorize();
let success = todoist.quickAdd(task);
if (success) {
console.log("Todoist task created: " + task);
}
else {
ctErrors++;
console.log("Todoist error: " + todoist.lastError);
}
}
else {
// do nothing with the line
}
}
Another thing is that I am trying to make a shortcut that adds to a specific project, section and label, how would I go about referencing specific sections and what is the best way to add a task?
I think that’s going to be where you are diverging as you are passing in some text, not an ID.
The support for Todoist actions in Shortcuts doesn’t look great, so you could take a look at utilising the URL scheme, or you could handoff to an action in Drafts and utilise the API integration as you are dong, but you would need to switch to using createTask() rather than quickAdd() as you want to access more of the functionality.
You can use labels in quick add using a similar process to projects (e.g. to add a task to project work use #work) for labels you prefix with @ (e.g. @local) For both projects and labels any that you reference have to have already been created in todoist, quick add won’t create them for you.