[SOLVED] Moralis Cloud Function Cannot Receive Params

Hi, Iโ€™m trying to call my Cloud Function. It is working without params, but when I use params, itโ€™s not received by the cloud function.

This is my Tryuser.js

import React from "react";
import Moralis from "moralis/dist/moralis.min.js";
import { useEffect } from "react";

export const TryUser = () => {
  useEffect(async () => {
    const params = { movie: "The Matrix" };
    const ratings = await Moralis.Cloud.run("averageStars", params);
    console.log(ratings);
  });

  return <div></div>;
};

And this is my cloud function

Moralis.Cloud.define("averageStars", async (request) => {
  logger.info("Hello World", request.params);
});

This is what the logger shows, it does not show any params

Please help.

you can try to use logger.info(JSON.stringify(request)) to see how that request looks like

Updated to this

Moralis.Cloud.define("averageStars", async (request) => {
  const logger = Moralis.Cloud.getLogger();

  logger.info("Hello World", JSON.stringify(request));
});

Still no result

Oh solved it by using

logger.info("Hello world" + JSON.stringify(request));

We must use โ€œ+โ€ sign instead of โ€œ,โ€ to display more than one string / parameter. And also needs to stringify if we have a JSON object.

logger.info doesnโ€™t support 2 parameters, only one parameter, you will not see the second parameter

1 Like