I want to test calling an API in a custom function for Google Sheets. code.gs
is as follows:
function TApi(input) {
var url = "https://api.nytimes.com/svc/search/v2/articlesearch.json";
url += '?' + $.param({
'api-key': "cdaa59fea5f04f6f9fd8fa551e47fdc4",
'q': "MIT"
});
$.ajax({
url: url,
method: 'GET',
}).done(function(result) {
return result;
console.log(result);
}).fail(function(err) {
throw err;
});
}
But when I call =TAPI()
in a sheet cell, it returns an error ReferenceError: "$" is not defined. (line 22).
I guess we need to add a link to JQuery. Does anyone know how to do this?