The library
You’ll find it here if you want to fork it, or you can include this resource
MjbiRDgq07ZNFaXn0OEKX-yz3TLx7pV4j
The API
EasyCron has a fairly straightforward API. This library provides a simple interface to it from GAS. I personally don’t use it, but following a few posts on the subject in the Google Apps Script community I thought I may as well create this for others to use. Please provide feedback via Google Apps Script community if you find it useful or otherwise.
Example
Before you start you should store your API key in your property service, as the example below. Here is how to schedule running a GAS webapp everyday at 12:30. It uses cron expressions which you can read about here.
function myFunction() { // some gas webapp var sc = "https://script.google.com/macros/s/AKfycbyNxrJg2SbjoKWJQgGxqjECkcA-A57xaoRQWzsJkTPbVyTWbCDi/exec"; // get my apiKey, which Im storing in my userproperties var easyCron = new EasyCron(JSON.parse(PropertiesService.getUserProperties().getProperty('easyCronKeys')).restAPIKey); // schedule it at 12:30 every day (see https://www.easycron.com/faq/What-cron-expression-does-easycron-support) var result = easyCron.add("myGASWebapp",sc,"30 12 * * *"); if(!result.ok) { throw (JSON.stringify(result)); } }
and here’s what it looks like on the easyCron console
Here’s some more methods available in the library
function test () { // some other things var easyCron = new EasyCron(JSON.parse(PropertiesService.getUserProperties().getProperty('easyCronKeys')).restAPIKey); // add something var id = easyCron.add("testcron","https://www.easycron.com/rest/list?token=4cf0ff7a668a141d5a81e2b6242952dc&sortby=name&page=1","0 0 * * 3").id; Logger.log(easyCron.enable(id)); // list all current cron jobs var jobs = easyCron.listAll(); jobs.forEach (function(d) { Logger.log(easyCron.disable(d[0].cron_job_id)); }); Logger.log(easyCron.disable(id)); // remove it Logger.log(easyCron.remove(id)); }