Execute is not a function

I’m trying to integrate with Express.js, and every time I encounter the following error:

TypeError: mondayClient.execute is not a function
at viewSecret (/home/ubuntu/quickstart-integrations/src/controllers/monday-controller.js:51:36)
at Layer.handle [as handle_request] (/home/ubuntu/quickstart-integrations/node_modules/express/lib/router/layer.js:95:5)
at next (/home/ubuntu/quickstart-integrations/node_modules/express/lib/router/route.js:144:13)
at authenticationMiddleware (/home/ubuntu/quickstart-integrations/src/middlewares/authentication.js:14:5)
at Layer.handle [as handle_request] (/home/ubuntu/quickstart-integrations/node_modules/express/lib/router/layer.js:95:5)
at next (/home/ubuntu/quickstart-integrations/node_modules/express/lib/router/route.js:144:13)
at Route.dispatch (/home/ubuntu/quickstart-integrations/node_modules/express/lib/router/route.js:114:3)
at Layer.handle [as handle_request] (/home/ubuntu/quickstart-integrations/node_modules/express/lib/router/layer.js:95:5)
at /home/ubuntu/quickstart-integrations/node_modules/express/lib/router/index.js:284:15
at Function.process_params (/home/ubuntu/quickstart-integrations/node_modules/express/lib/router/index.js:346:12)

I have the following code:
const initMondayClient = require(“monday-sdk-js”);
const mondayClient = initMondayClient();

async function viewSecret(req, res) {
const { authorization } = req.headers;
console.log(‘Entro en la ruta’)

mondayClient.setToken(authorization);

try {
console.log(‘entro en try de viewSecret’)
const response = mondayClient .execute(“notice”, {
message: “AQUI QUIERO VER EL SECRETO”,
type: “info”,
timeout: 90000000,
});

return response;

} catch (err) {
console.error(err);
return res.status(500).send({ message: ‘internal server error’ });
}
}

and I have installed “npm install monday-sdk-js”.

Why is this happening to me?

I’m no expert here, but it looks like you are mixing up server side and client side code.

This is an example which works on the server:

monday.setToken('ac5eb492f8c...');
monday.api('query { users { name } }').then(res => {...})

On the other hand, I’m guessing that monday.execute is client side only as it updates the momday.com UI (rather than your app’s UI) with e.g. a message:

monday.execute("notice", { 
   message: "I'm a success message",
   type: "success", // or "error" (red), or "info" (blue)
   timeout: 10000,
});

gives:

My guess is that monday.execute works on the client-side only by using window.postMessage or BroadcastChannel behind the scenes.

Make sure that you try the monday.execute on the client-side.

Actually, you should take a look at the source code for monday.execute

This line:

async function execute(data, token, options = {}) {

…suggests that you can pass a token through from the server side.