I found this script in the examples thread and wanted to make a Hello World widget. I set up a base in Airtable got my API key and set up the script to connect to my base but I get nothing in Scriptable. No data retrieved and no error message.
// Variables used by Scriptable.
// These must be at the very top of the file. Do not edit.
// icon-color: deep-purple; icon-glyph: magic;
let baseURL = "https://api.airtable.com/v0/*********************/Books?maxRecords=100&view=Grid%20view"
let r = new Request(baseURL);
r.headers = { 'Authorization': 'Bearer key**************'};
let json = await r.loadJSON();
let titles = json['records'];
let randomBook = (titles[Math.floor(Math.random()*titles.length)]);
let titleText = randomBook['fields']['Title'];
let bookAuthor = randomBook['fields']['Author'];
let widget = createWidget();
if (config.runsInWidget) {
let widget = createWidget();
Script.setWidget(widget);
Script.complete();
}
function createWidget() {
let w = new ListWidget();
let widgetText = w.addText(titleText);
widgetText.textSize = 15;
let widgetSubText = w.addText(bookAuthor);
widgetText.textSize = 13;
return w
}
In the cli I can use curl to connect and receive the records from the base but nothing in Scriptable.
What have I got wrong?