I’m trying to create a widget that reads a json file from a url.
My browser can read the json file no problem.
I’m trying to get this example to work in scriptable but I receive the error message in the subject.
I’m guessing it thinks the variable “url” is not defined but it appears to be defined. Am I missing something obvious?
** // const url = "https://www.github.com/marcjulianschwarz/code/sample.json";
const url = "http://192.168.5.56/test/output.json";
async function getData(url){
let request = new Request(url);
data = await request.loadJSON();
return data;
}
function processData(data){
// Process your data here
// ...
return processedData;
}
function createWidget(data){
var widget = new ListWidget();
var text = widget.addText(data.sample);
text.textColor = Color.dynamic(Color.black, Color.white);
text.font = Font.regularRoundedSystemFont(13);
widget.backgroundColor = Color.dynamic(Color.white, Color.black);
return widget;
}
let data = await getData(url);
let processedData = processData(data);
let widget = await createWidget(processedData);
Script.setWidget(widget);
Script.complete();**