How to save objects in the backend

Hi guys, as the title says, I have a node server running in my backend that controls an external database, and I want to modify objects in the moralis database, how can I give a role for this api to manipulate the objects, I had not had inconvenience because I worked with the default permissions to write and read public, but for production I must change them, it is a nodejs api

The issue: “Permission denied for action update on class NFT”.

you can use the master key in backend and in that case you bypass any permission

const Moralis  = require('moralis/node');
const serverUrl = process.env.MORALIS_SERVER_URL;
const appId = process.env.MORALIS_API_ID;
const masterKey = process.env.MORALIS_MASTER_KEY
Moralis.start({ serverUrl, appId, masterKey});


const doSomething = async() =>{    
    const query = new Moralis.Query("NFT")   
    const result = await query.find()    
    result[1].set("name","test")
    result[1].save()
}

doSomething()

I was trying that but it returns this:
" Error: Permission denied for action update on class NFT. "

and also try updating the moralis library to 1.3.2

https://docs.moralis.io/moralis-server/cloud-code/cloud-functions#using-the-master-key-in-cloud-code

you need to use the master key for .save

1 Like