Drafts Action Directory

Todoist Add

Posted by @joelberger76, Last update 11 months ago

Add tasks to Todoist via Quick Add API. See the following link for help with syntax:

https://support.todoist.com/hc/en-us/articles/115001745265-Task-Quick-Add

Install

Steps

  • script

    var todoistURL = "https://todoist.com/api/v7/quick/add";
    
    //Read token from file in iCloud
    //var fmCloud = FileManager.createCloud(); // iCloud
    //var token = fmCloud.read("/TodoistToken.txt");
    //if (token == "undefined") {
      //console.log("File not found");
      //context.fail();
    //}
    
    var credential = Credential.create("Todoist", "Todoist API Key");
    credential.addPasswordField("apiKey", "API Key");
    credential.authorize();
    var token = credential.getValue("apiKey");
    
    var lines = draft.content.trim().split('\n');
    var task = '';
    for(var ix in lines) {
       task = lines[ix];
    
       //Todoist parsing doesn't treat Tod and Tom as dates
       task = task.replace("Tod", "tod");
       task = task.replace("Tom", "tom");
    
       // create HTTP and make POST request to Todoist
       var http = HTTP.create();
       var response = http.request({
         "url": todoistURL,
         "method": "POST",
         "encoding": "form",
         "data": {
            "token": token,
            "text": task
         },
       });
    
       // log result
       console.log(response.statusCode);
       console.log(response.responseText);
    
       // if not 200 OK, fail the action
       // Otherwise Todoist successfully received post
       if (response.statusCode != 200) {
    	   context.fail();
       }
    }

Options

  • After Success Trash
    Notification Info
    Log Level Info

Comments

Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.