NFTOwners beforesave function failing after update


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”:“",“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; 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.“error”);;;

  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'

1 Like
async function httpGet2(url) {
  return await Moralis.Cloud.httpRequest({
    url: url,
    headers: {
      method: "GET",
      accept: "application/json",
    .then((httpResponse) =>
    .catch((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?

still stuck until now yes it’s been over 1 hour. despite the log showed confirmed balance.

I’ve created a new server which fixed the problems, but it’s worth mentioning if this was an in production website this would have been a disaster.

when you are using local Ganache you have to create a new Moralis dev server every time you start with a new instance of Ganache, because the old Moralis dev server will still keep track of previous transactions from previous Ganache instance and things will not work well (I don’t know if this was your case)

wasn’t using ganache I was on a testnet