I wrote a custom function in Apps Script which constructs a query using the function arguments and calls BigQuery service (for which I enabled using an API key) supplying the query. But when I used the function in the spreadsheet, it always returned server error.
error: We're sorry, a server error occurred. Please wait a bit and try again.
Here is my code (it works when I run it in the debugger by supplying the variables manually):
function GetAge(first_name, last_name) {
var select_text = "SELECT first_name, last_name, age FROM Testing.FullNames WHERE ";
var filter_text = "first_name = '" + first_name + "' AND last_name= '" + last_name + "' ";
var group_text = "GROUP BY 1,2;";
var query_text = select_text + filter_text + group_text;
var query = {'query': query_text};
var response = BigQuery.Jobs.query('<My Project Id>', query);
var value = response.getRows()[0].getF()[2].getV();
return value;
}