Ran cloud function getNft for user undefined

i am calling my moralis cloud functions via api with postman but i have set the acl on my objects so it did’nt returns the results.
My question is how to call the api for a user so it could not say Ran call function for user undefined
Ran cloud function getNft for user undefined with:
Input: {“tokenId”:29,“user”:“NDfNg3ntbkgtnABfWMzobfGRe”,"_ApplicationId":“Egd4T5joZLFXPNyixev7xZCdrX27mymyOxrnVegE”}
Result: []

You can pass the wallet address through cloud function params and use the address in the getNFT options.

it return the same response if i pass wallet address with key user in params

@johnversus

can you share your cloud function code

async function getNft(request) {

const logger = Moralis.Cloud.getLogger();

logger.info("my log"+ JSON.stringify(request));

const nftData = Moralis.Object.extend("NftMeta");

const query = new Moralis.Query(nftData);

query.limit(200);

query.equalTo("tokenId",String(request.tokenId));

const myData = await query.find();

return myData;

}
@johnversus
Here my cloud function but i set acl for a specific user on that objects so i want to specify the user while calling cloud function

so i can see the user here insead of undefined

Your cloud function should be in this syntax, with Moralis.Cloud.define

Moralis.Cloud.define("getNft", async (request) => {
  const logger = Moralis.Cloud.getLogger();
  logger.info("my log" + JSON.stringify(request));
  const nftData = Moralis.Object.extend("NftMeta");
  const query = new Moralis.Query(nftData);
  query.limit(200);
  query.equalTo("tokenId", String(request.params.tokenId));
  const myData = await query.find();
  return myData;
});

and while calling the function form postman use this format, since it is a get request.
SERVER_URL/server/functions/getNft?_ApplicationId=APPId&tokenId=10

I passed only tokenId here in the URL as your cloud function is only using tokenId

@johnversus
i defined my cloud function separately in cloud file on my local IDE, the code of that cloud file is here
Moralis.Cloud.define(“eventSyncing”, async (request) => {

return getEvents(request.params);

});

Moralis.Cloud.define(“syncNftData”, async (request) => {

return syncNftData(request.params);

});

Moralis.Cloud.define(“updateMetaData”, async (request) => {

return updateMetaData(request.params);

});

Moralis.Cloud.define(“getNft”, async (request) => {

return getNft(request.params);

});

As you seen in screenshot of my logs i marked the line of

> Ran cloud function with user undefined

my issue is to access the data from database with acl permissions, only specific user can read the data but i dont know how to specify the user while calling cloud function api

oh ok…Try adding useMasterKey in find()

await query.find({ useMasterKey: true });

You can read rows with ACL using masterkey, if that what the issue is.

so after this also i have to pass master key in request params ?

no, just include { useMasterKey: true } in the cloud function only, when using find()

after this anybody can access my objects so that destroy functionality of acl
i need only authenticated user to access the objects

@cryptokid can you please answer this

I don’t know the exact question. You can use CLP and ACL for access settings. You can also do a check in cloud code to see if the user is authenticated and continue after that with master key.

@cryptokid
then how to check in cloud code that user is authenticated or not

You check the information that is available in request object

here you can see i checked by logger.info(request) but it returns the same json object that i pass in params

Usually you have to use JSON.stringify(request).

I’m not sure what you are doing. You can call simple js functions in cloud code too.

Can you rephrase the issue that you have?

i set the acl on my objects for a specific user and this cloud function reads the data from that class but due to acl it does not allow to read the data when i call that cloud function via rest api from postman
So the issue is how specify the authenticated user in api call that acl allow him to read the data from class.
any auth token or something else i pass in request that allows to read the data secured with acl

you could look in network tab in a browser for when an authenticated user makes a request, see there what info is required (probably the session token), and make the same type of request with similar data in postman