NFTOwners beforesave function failing after update

mine doesn’t even if I put it on it’s own function this is the error I’m getting now when I run it

2021-10-18T17:49:30.738Z - Error: Invalid function: “get_token_metadata”
at handleCloudFunction (/moralis-server/lib/Routers/FunctionsRouter.js:119:13)
at /moralis-server/lib/PromiseRouter.js:85:20
at processTicksAndRejections (internal/process/task_queues.js:95:5)

Maybe there is some error somewhere, if you add my function in you cloud code I expect it to work.

as I said I did add it exactly same with static url still same result

If you copy exactly my code you get that error? Other functions work well?

yes

2021-10-18T18:32:18.462Z - Error: Invalid function: “get_token_uri”
at handleCloudFunction (/moralis-server/lib/Routers/FunctionsRouter.js:119:13)
at /moralis-server/lib/PromiseRouter.js:85:20
at processTicksAndRejections (internal/process/task_queues.js:95:5)

Strange, are you sure you are connected to the right Moralis server? You get same error if you put there a random function name?

yes sure it’s the correct server I’m just initiating and running from console at this point

this does work anyway so I might just change my before save to include it.

Moralis.Cloud.define(“testMetadata”, async (request) => {
const { chain, tokenAddress, tokenId, } = request.params;
return await Moralis.Web3API.token.getTokenIdMetadata({ address: tokenAddress, token_id: tokenId, chain: chain}).then((result) => {
return result;
});
});

well now trying to incorportate the very same code into the before save results in

  1. 2021-10-18T21:08:30.535Z - beforeSave failed for BscNFTOwners for user undefined: Input:

{“name”:“Blockchain Factory”,“symbol”:“BLCKCHN”,“token_uri”:“https://ipfs.moralis.io:2053/ipfs/QmWantQC68Re6vWpn1PktgtGJoe1mPEJ71yvNdatys1j1K",“token_id”:“124”,“token_address”:“0x668aed884e1ebfa5dab26fc80ab0f8ecea59aa2b”,“owner_of”:“0x4771ff1f558b3cc9996ec030fca95fd672425ef6”,“block_number”:13343001,“amount”:“1”,“contract_type”:"ERC721”} Error: {“message”:"[object Object]",“code”:141}

here is the beforeSave()

Moralis.Cloud.beforeSave(“BscNFTOwners”, async (request) => {
const tokenAddress = request.object.get(‘token_address’);
const tokenId = request.object.get(‘token_id’);
const tokenUri = request.object.get(‘token_uri’);
if (!tokenUri) return;
// var dataFromURI = await httpGet(tokenUri);
var dataFromURI = await Moralis.Web3API.token.getTokenIdMetadata({ address: tokenAddress, token_id: tokenId, chain: ‘bsc testnet’}).then((result) => {
return result.metadata;
});

request.object.set("metadata", dataFromURI);

});

you could add some lines with logger.info(JSON.stringify(variable_name)); to see how far it gets in execution

even with ur code it’s not returning anything useful here is a sample

  1. 2021-10-18T21:31:49.200Z -
  2. 2021-10-18T21:31:49.200Z -
  3. 2021-10-18T21:31:49.200Z - error

the result could also depend on the url that it tries to access, sometimes that url could not work

except that all and every URL which is just files on the server itself btw not working I’m kind of giving up here this is killing the site that is using it already.

Can you add more logging? like the url that it is tried to get accessed before it tries to access it.

That is what is only returning from your function with added URL Logging.

logger.info(“error”);
logger.info(tokenUri);
logger.info(httpResponse);

  1. 2021-10-19T07:32:37.130Z -
  2. 2021-10-19T07:32:37.130Z -
  3. 2021-10-19T07:36:24.338Z -
  4. 2021-10-19T07:36:24.337Z - error

I doesn’t look good, can you paste the function that you use now?

function httpGet2(url) {
	return Moralis.Cloud.httpRequest({
		"url": url,
		"headers": {
			'method': 'GET',
			'accept': 'application/json'
		}
	}).then(function(httpResponse){
		return httpResponse.data;
	},function(httpResponse){
		logger.info("error");
		logger.info(url);
		logger.info(httpResponse);
	});

}
1 Like
async function httpGet2(url) {
  return await Moralis.Cloud.httpRequest({
    url: url,
    headers: {
      method: "GET",
      accept: "application/json",
    },
  })
    .then((httpResponse) => httpResponse.data)
    .catch((error) => logger.info(error));
}

this doesn’t fail but I see on the console balance is confirmed of the newly created NFT however it’s still in pending table even after confirmation. I’ve tried few times already with same result for some reason.

are they stuck or are in the “pending” table for too long?