// Modified from @mutsuda's https://medium.com/@mutsuda/create-an-ios-widget-showing-google-spreadsheets-data-856767a9447e // Modified from @levelsio's https://gist.github.com/levelsio/a1ca0dd434b77ef26f6a7c403beff4d0 // By @daolf // Prerequisite: install Scriptable @ https://apps.apple.com/us/app/scriptable/id1405459188 const API_TOKEN = "CHARTMOGUL_TOKEN" const API_SECRET = "CHARTMOGUL_SECRET" // Recreating a basic auth with Scriptable lib const auth = "Basic " + btoa(`${API_TOKEN}:${API_SECRET}`); const currentYear = new Date().getYear(); const startDate = `${currentYear}-01-01` const endDate = `${currentYear}-12-31` const endpoint = `https://api.chartmogul.com/v1/metrics/mrr?start-date=${startDate}&end-date=${endDate}` async function loadItems() { let at = endpoint let req = new Request(at) req.headers = {"Authorization" : auth} let response = await req.loadJSON() return response } // Request the MRR data let json = await loadItems() MRR = Math.floor(json["summary"]["current"] / 100).toString() // Create the widget let w = new ListWidget() w.backgroundColor = new Color("#000000") // Formating number i.e 19000 -> $19,000 t = w.addText(`\$${new Intl.NumberFormat('en-US').format(MRR)}`) t.textColor = Color.white() t.font = new Font("Avenir-Heavy",24) Script.setWidget(w) Script.complete()