Action

Unchecked Tasks to Todoist

Posted by @RosemaryOrchard, Last update over 5 years ago

Based on Version 2 of the Todoist Quick Add API Action.

This action takes all of the incompleted tasks in a Draft, and adds them to Todoist:
- [ ] task 1
- [ ] task 2
- [x] task 3
Task1 and task2 would be added here.

Because it uses the quick add API the tasks can be in the following format:
- [ ] Buy beer tomorrow 1pm #Party p1
- [ ] Call Pete #Work friday 3pm

And it should add them to the right project, interpret times, etc.

You will need to add your Todoist API Token into the script where indicated.

Steps

  • script

    var credential = Credential.create("Todoist", "Todoist API");
    
    credential.addTextField("token", "Token");
    
    credential.authorize();
    
    // check to see if draft is blank
    var content = draft.content;
    var check = content.length;
    
    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 = draft.content.split("\n");
    
    var http = HTTP.create(); // create HTTP object
    
    var params = {"token":credential.getValue("token")};
    
    for (var line of lines) {
    
    	if (line.startsWith("- [ ] ")) {
    		params["text"] = line.replace("- [ ] ", "");
    		
    		var response = http.request({
    		  	"url": "https://todoist.com/api/v7/quick/add",
    		  		"method": "POST",
    		  	"data": params
    		});
    		
    		if (response.success) {
    			console.log(response.statusCode);
    		} else {
    		  	console.log(response.statusCode);
    		  	console.log(response.error);
    		}
    	}
    }

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.