I'm writing a cloud code function that calls the /schemas endpoint while processing requests. Since this function requires the masterKey, I thought I'd use Parse.Cloud.httpRequest to make the request, but HTTPOptions doesn't seem to have a useMasterKey property.
How would I go about doing something like this? Hard coding the masterKey in the cloud code function's request headers seems like a bad idea.
Yes, hard coding in the master key is a bad idea... glad you didn't go that route.
Your cloud code can USE the master key without having it passed in by the client making the request, though I have not tried httpRequest as a function that utilizes the master key.
Some examples
query.find({useMasterKey:true});
object.save(null,{useMasterKey:true});
Parse.Object.saveAll(objects,{useMasterKey:true});
You are probably using environment variables to initialize the server, no? If not, you should, instead of hard coding in your index.js.
This way, you can add the master key to the headers of your http request by using process.env.MASTER_KEY or something similar to what you have.
@natanrolnik ah yes, that's perfect. Thanks!
We could also add the useMasterKey option to the Parse.Cloud.httpRequest options ;)
There should be a section in the cloud code guide that explains how to use this, just as @MobileVet posted above. With some nice examples :-)
Feel free to edit the guides in the docs repo and open a PR
Most helpful comment
We could also add the useMasterKey option to the Parse.Cloud.httpRequest options ;)