Skip to main content

Execute is not a function

  • June 26, 2023
  • 4 replies
  • 685 views

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?

4 replies

dvdsmpsn
Forum|alt.badge.img+1
  • Participating Frequently
  • June 26, 2023

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.


dvdsmpsn
Forum|alt.badge.img+1
  • Participating Frequently
  • June 26, 2023

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.


Binatica
Forum|alt.badge.img
  • New Participant
  • June 13, 2024

Hey @dvdsmpsn
So it’s possible to use monday.execute from node server somehow?
Thanks


dvdsmpsn
Forum|alt.badge.img+1
  • Participating Frequently
  • June 13, 2024

Oh, I don’t think so – I may have gotten my wires crossed, Its worth trying to understand the source anyway, as it might help you i other ways 🙂