Drafts Action Directory

Add Single Todoist

Posted by @nahumck, Last updated: 2018-07-04 15:42:59 UTC

Send a single task to Todoist.

Install

Steps

  • script

    // Todoist Quick Add
    
    var credential = Credential.create("Todoist", "Todoist API");
    
    credential.addTextField("token", "Token");
    
    credential.authorize();
    
    // Single Task script
    
    // If text is selected, use as task name
    // Otherwise, leave it blank
    var sel = editor.getSelectedText()
    if (sel.length == 0) {
    	var task = "";
    }
    else {
    	var task = sel;
    }
    
    /* ---- Prompt ---- */
    
    var p = Prompt.create();
    p.title = "Task to Todoist";
    p.addTextField("task", "Task", "",{"placeholder":"task w/ date, priority, project, etc."});
    p.addTextView("note", "Note", "", {"height": 50});
    p.addButton("Send to Todoist");
    var con = p.show();
    
    if (con) {
    	var task = p.fieldValues["task"];
    	var note = p.fieldValues["note"];
    
    	// Call API
    	var http = HTTP.create(); // create HTTP object
    	var response = http.request({
    	  "url": "https://todoist.com/api/v7/quick/add",
    	  "method": "POST",
    	  "data": {
    	    "token":credential.getValue("token"),
    	    "text":task,
    	    "note":note
    	  },
    	});
    }
    else {
    	context.cancel();
    }

Comments

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