Is it possible to modify data in beforeSave cloud function?

Hey,
I would like to modify incoming data by using the beforeSave cloud function. What I want to do is get the current price of BNB and save it with the incoming data. Would this be possible and how would I accomplish this?

Thanks

Yes you can. You can request.object.set("KEY", "VALUE") in the beforeSave.

Thanks,
How would I run this in a cloud function?
WBNBprice = await Moralis.Web3API.token.getTokenPrice({address: “0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c”, chain: “bsc”});

doesn’t work like that in cloud code?

I haven’t tried it yet. I can’t save any new cloud functions in the old interface. I have to setup a local IDE sync to do it. I will attempt it tomorrow. Thanks.

It works fine. You can have something like this

  const WBNBprice = await Moralis.Web3API.token.getTokenPrice({
    address: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
    chain: "bsc",
  });

  request.object.set("WBNBPrice", WBNBprice.usdPrice);

This might be helpful https://youtu.be/rJ88MPODVRg

You can still use the old UI if needed to change the cloud code.