Append to Existing Microsoft Todo List

I use Microsoft Todo for Task Management, and I have read the integration guide.

Am curious if anyone has already created a Draft Action that appends to an existing list?

For example, if I have a draft like so:

print latest report @marketing

I want the task “print latest report” to be added to the existing @marketing list in Microsoft Todo.

Before I try to script up on my own, wanted to check to see if this might already exist from someone out there.

thanks.

I’ve not seen any similar examples for Microsoft Todo, but I wouldn’t think it would be too bad to build. It’s a bit more advanced, but you might look at the Things Parser action, which has some similar parsing of values from lines to construct tasks for Things.

Ethan, see if this helps get you there. I wrote a script kind of like this before, but that took a dedicated folder (list) variable. Here’s a modification that parses the list name from the draft as you described — but I don’t have my API key handy to try it out, so this looks right but it’s untested.

let api = "YOUR_API_KEY";

let firstLine = draft.processTemplate("[[line|1]]"),
	splitLine = firstLine.split("@"),
	current = splitLine[0].trim(),
	folder = splitLine[1] ? splitLine[1].trim() : "";

if (!folder) {
	alert("Folder not provided in the draft");
	context.fail();
} else {
	let req = new HTTP(),
		result = req.request({
			encoding: "json",
			method: "POST",
			data: {
				title: current,
			},
			headers: {
				"Content-type": "application/json; charset=UTF-8",
				"Authorization": `Bearer ${api}`,
			},
			url: `https://graph.microsoft.com/v1.0/me/todo/lists/${folder}/tasks`,
		});

	if (result.success) {
		alert(result.responseText);
	} else {
		alert(`Error: ${result.statusCode} - ${result.error}`);
	}
}

Good luck!

Just FYI, Drafts provides a wrapper class for working with the ToDo API that handles authentication and provides some convenience functions.

1 Like