[SOLVED] Cloud function not working

i’m using aftersave trigger through cloud code but it’s not triggered and no update at log , i also tried it by setting webhook through dashboard UI for the same in that case my webhook url called but no parameter received at the webhook url end, here is my cloud code i’m providing below

Moralis.Cloud.afterSave("BscTokenTransfers", async function (request) {
  const confirmed = request.object.get("confirmed");
  const logger = Moralis.Cloud.getLogger();
  if (confirmed) {
  
    logger.info("before save user");
   logger.info("before save user done");
   logger.info(JSON.stringify(request.object));
  } else {
   
  }
});

I would expect afterSave to trigger.
Can you add a log line on the first line of that afterSave trigger?

webhook worked for the above mentioned issue.
But cloud functions still not working , if i’m using Cloud Function interface for writing cloud function code then it works properly without any error but when i upload the same cloud Function code through moralis-admin-cli it gives invalid function error on execution.
sample code for test cloud function is


Moralis.Cloud.define("test", async (request) => {
    
    const logger = Moralis.Cloud.getLogger();
    logger.info("In test");
    
 });

the response i received at error log given below

2022-08-11T10:19:27.802Z - Error: Invalid function: "test"
    at handleCloudFunction (/moralis-server/lib/Routers/FunctionsRouter.js:201:13)
    at /moralis-server/lib/PromiseRouter.js:85:20
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

you can use the legacy admin interface: legacy.moralis.io to see how the cloud code looks like.

when you upload a new cloud code, you will get that kind of error while the cloud code is updated

legacy.moralis.io shows only following code

/******/ (() => { // webpackBootstrap
/******/ 	/* webpack/runtime/compat */
/******/ 	
/******/ 	if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
/******/ 	
/************************************************************************/
var __webpack_exports__ = {};

module.exports = __webpack_exports__;
/******/ })()
;

this means that no cloud code was uploaded, you have to check the command that you used to upload the cloud code with moralis-admin-cli

command i’m using and the output of the command is :

C:\WINDOWS\system32>moralis-admin-cli watch-cloud-folder --moralisApiKey <serverapikey> --moralisApiSecret <serversecret> --moralisSubdomain hgsa19rteamv.usemoralis.com --autoSave 1 --moralisCloudfolder C:\Desktop\test.js
ncc: Version 0.29.2
ncc: Compiling file index.js into CJS
Changes Uploaded Correctly

you have to give it a folder as parameter, and not a file, at least on how that command is run

1 Like

thanks! it’s working now

1 Like