Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From Cloud Code, how can I query for Installations matching a set of Users?

I'm using a standalone Parse server, trying to send a push notification to multiple Installations.

Parse Server won't let me query the Installation collection from Cloud Code, returning the following error:

Error handling request: ParseError {
  code: 119,
  message: 'Clients aren\'t allowed to perform the find operation on the installation collection.' } code=119, message=Clients aren't allowed to perform the find operation on the installation collection.

The query in Cloud Code looks like this:

var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.containedIn('user', users);
pushQuery.find({ ...

What's the proper way to get a list of Installations for a set of Users and send pushes to all of them?

I've also tried to get Cloud Code to use the masterKey by calling Parse.Cloud.useMasterKey(); immediately before the query. No effect and the master key is not included in the query request headers.

like image 730
Gabriel Bauman Avatar asked Jan 12 '17 00:01

Gabriel Bauman


1 Answers

This is because Parse.Cloud.useMasterKey() is deprecated since Parse-server version 2.3.0. You now need to make use of useMasterKey: true in your query.

Eg:

var pushQuery = new Parse.Query(Parse.Installation);
pushQuery.containedIn('user', users);
pushQuery.find({useMasterKey: true }).then(function(results) {
like image 160
Cliffordwh Avatar answered Jan 19 '23 04:01

Cliffordwh