Trying to use SerpAPI for an endpoint

I’m completely new to JS/Node.js but so far I got this notebook/endpoint working fairly well:

However, since I’m learning as well, I wanted to use the SerpAPI properly, so I wrote this notebook:

that’s NOT working. It gives:

"schemaVersion": 1,
"label": "citations",
"message": "[object Promise]", // <--- it should be 1412 here
"color": "orange",
"cacheSeconds": 2592000

Here’s my endpoint code that I’d like make it work:

const SerpApi = require('google-search-results-nodejs');
const search = new SerpApi.GoogleSearch(process.env.api_key);
function promisifiedGetJson(params) {
    return new Promise((resolve, reject) => {
        try {
            search.json(params, resolve)
        } catch (e) {
async function main(params) {
    try {
        // `const data = await fn()` is same as `fn().then(data)`
        const data = await promisifiedGetJson(params);
        const total = data.organic_results[0];
        // console.log(total);
        return total;
    } catch (error) {
        console.error("there was an error:", error);
let params = {
    engine: "google_scholar",
    as_ylo: "2012",
    as_yhi: "2012",
    q: '"ACPYPE-Antechamber python parser interface"',
    hl: "en",
const tot = main(params);
const obj = { "schemaVersion": 1, "label": "citations", "message": tot.toString(), "color": "orange", "cacheSeconds": 2592000 };
exports.endpoint = function (request, response) {

What am I be missing here please?

const tot = main(params); is your problem.
main is an async function which means it returns a promise. You must await the promise to get the value:
const tot = await main(params);

Brilliant! It’s working! Many thanks!