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

1

7

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.

Aerobiosis answered 12/1, 2017 at 0:1 Comment(3)
The error mentions clients aren't allowed to use the find query. How are you calling the cloud function from the client?Brookins
This is all in a Parse.Cloud.afterSave() callback. The client calls the server to update an object, and I'm trying to run this query after the save. The query is not run by the client directly.Aerobiosis
weird that you are getting the client error then. Could you put the query somewhere other than the callback ?Carduaceous
P
6

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) {
Provence answered 12/1, 2017 at 6:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.