You cannot use [object Object] as a query parameter

Hey. I’m trying to create a cloud function, but have ran into an issue - it throws Error: You cannot use [object Object] as a query parameter.. If anyone can help, that would be great. Thanks in advance.

Moralis.Cloud.define("returnBalanceOfUser", async (userid,contractAddress,BscChain) => {
   const query = new Moralis.Query("User");
    query.equalTo("userid", userid);
    const results = await query.find({useMasterKey:true});
    var bal = 0;
    if(results.length > 0){
        for (let i = 0; i < results.length; i++) {
            const object = results[i];
            const options = { chain: BscChain, address: object.get("ethAddress")}
            const balances = await Moralis.Web3API.account.getTokenBalances(options);
            const parsed = JSON.parse(balances);
                
            for(var j = 0; j < parsed.length; j++){
                if(parsed[j]["token_address"] == contractAddress){
                    bal += parsed[j]["balance"];
                    break;
                }

            }
        }
    }
    else bal = -1;
    return bal;
});
1 Like

Hey @Pantk

Try to specify:

const parsed = JSON.parse(balances.result);