Getting the token id from the request object in 'aftersave'

How do i access the token_id value in the Moralis.cloud.afterSave?

Moralis.Cloud.afterSave("EthNFTOwners", async (request) => {
  const ethAddress = await request.object.get("owner_of");
  logger.info("ethAddress", ethAddress);
  const tokenId = await request.object.get("token_id");
  logger.info("tokenId", tokenId);
}

Looking in the logger the tokenId is null

what am i doing wrong?

Hey @deadLuchador

You need to Stringify objects to see them in the logger.

JSON.stringify()

UPD: Have you imported logger?

Moralis.Cloud.getLogger()

Hope this will help you! :man_mechanic:

Hey @Yomoo,

I have defined the logger outside of the cloud function, i’ve moved it inside now and used JSON.stringify() but still nothing in the logs.

Am i defining the ethAddress and tokenId correctly for EthNFTOwners ?

Moralis.Cloud.afterSave("EthNFTOwners", async (request) => {
  const logger = Moralis.Cloud.getLogger();
  const ethAddress = await request.object.get("owner_of");
  logger.info("ethAddress", ethAddress);
  const tokenId = await request.object.get("token_id");
  logger.info("tokenId --->", JSON.stringify(tokenId));
  logger.info("ethAddress --->", JSON.stringify(ethAddress));
}

This is what i see in the logs

I realised that i can’t pass in more than one variable to the logger.

so

logger.info(JSON.stringify(tokenId))

works as expected

@deadLuchador

Great job! :muscle:

Happy BUIDLing :man_factory_worker: