getInventory is invalid function in Cloning Rarible tutorial

When I leave the cloud function of getInventory only it is working fine, but when I had the other 2 before save it is saying invalid function getInventory

my cloud function:

Moralis.Cloud.define("getInventory", async (request) => {
  
  const query = new Moralis.Query("EthNFTOwners");
  query.equalTo("contract_type", "ERC721");
  query.containedIn("owner_of", request.user.attributes.accounts);
  const queryResults = await query.find();
  const results = [];

  for (let i = 0; i < queryResults.length; ++i) {
    results.push({
    	"id" : queryResults[i].attributes.objectId,
        "tokenId" : queryResults[i].attributes.token_id,
        "tokenAddress" : queryResults[i].attributes.token_address,
        "symbol" : queryResults[i].attributes.symbol,
        "tokenUri" : queryResults[i].attributes.token_uri
    });
  }
  return results;
});

 
Moralis.Cloud.beforeSave("ItemsForSale", async (request) => {
  
  const query = new Moralis.Query("EthNFTOwners");
  query.equalTo("token_address", request.object.get('tokenAddress'));
  query.equalTo("token_id", request.object.get('tokenId');

  const object = await query.first();
  if(object){
	 const owner = object.attributes.owner_of;
     const userQuery = new Moralis.Query(Moralis.User);
 	 userQuery.equalTo("accounts", owner);
  	 const userObject = await userQuery.first({useMasterKey:true});
    if(userObject){
    	request.object.set('user', userObject);
    }
    request.object.set('token', object);
  }
 
});

Moralis.Cloud.beforeSave("SoldItems", async (request) => {
  
  const query = new Moralis.Query("ItemsForSale");
  query.equalTo("uid", request.object.get('uid'));

  const item = await query.first();
  if(item){
     request.object.set('item', item);
     item.set('isSold', true);
     await item.save();
    
     const userQuery = new Moralis.Query(Moralis.user);
 	 userQuery.equalTo("accounts", request.object.get('buyer'));
  	 const userObject = await userQuery.first({useMasterKey:true});
    if(userObject){
    	request.object.set('user', userObject);
    }
  }
 
});

my main.js:

loadUserInventory = async () => {
    const ownedItems = await Moralis.Cloud.run("getInventory");
    console.log("INVENTORY", ownedItems);
    ownedItems.forEach(item =>{
        getAndRenderItemData(item,renderUserItem);
    })
}

It looks like your cloud code is invalid, one problem is on this line:
query.equalTo("token_id", request.object.get('tokenId');
where there are not enough parentheses. If you look on your admin panel, you will see a warning sign for you server that will tell you that your cloud function code is invalid.

1 Like

Thank you! totally missed that.