[SOLVED] Why is master key not working?

I have a cloud function that adds records to the “Participant” table. It’s working fine when I turn on all permissions for the public. But when I leave just “read” permission ticked it stops working even though I’m using the master key. What could be the problem?

image

  const ParticipantTable = Moralis.Object.extend("Participant");
  const participantInstance = new ParticipantTable();
  participantInstance.set("a", a, { useMasterKey: true });
  participantInstance.set("b", b, { useMasterKey: true });
  participantInstance.set("c", c, { useMasterKey: true });
  participantInstance.set("d", d, { useMasterKey: true });
  participantInstance.set("e", e, { useMasterKey: true });
  participantInstance.set("f", f, { useMasterKey: true });
  participantInstance.set("g", g, { useMasterKey: true });
  await participantInstance.save({ useMasterKey: true });

I’m triggering this function via a job:

Moralis.Cloud.job("addParticipantJob", (request) => {
  const run = async () => await Moralis.Cloud.run("addParticipant");
  return run();
});

Thank you

For save master key is the second parameter end not first

Thank you I changed to participantInstance.save(null, { useMasterKey: true }); and it worked.

1 Like