Parse-server: getting an error when sending push to multiple recipientIds

Created on 5 Apr 2016  路  31Comments  路  Source: parse-community/parse-server

Parse.Cloud.define("sendPush", function(request, response) {

var sendUserId = request.params.userId;
    var msg = request.params.message;

var query = new Parse.Query(Parse.Installation);
query.equalTo('userId', sendUserId);

    Parse.Push.send({
            query: query,
            data: {
                    alert: msg,
                    sound: 'default'
            }
    }, {
            success: function() {
                    // Push was successful
                    response.success("Push sent");
            },
            error: function(error) {
                    // Handle error
                    response.error(error);
            },
            useMasterKey: true
    });

});

/////// Android Code

public static void sendPush(final Context context, String message, String senderId) {

// String channel = "parse_user_channel_";
final Map params = new HashMap<>();
// params.put("accountId", channel);
params.put("message", message);
// params.put("senderName", senderName);
params.put("userId", senderId);
// params.put("useMasterKey", true);//Must have this line

  ParseCloud.callFunctionInBackground("sendPush", params, new FunctionCallback<String>() {

// public void done(String result, ParseException e) {
// if (e == null) {
// Toast.makeText(context, "HEHE", Toast.LENGTH_SHORT).show();
// Log.d("ANNOUNCEMENT" ,"SUCCESS");
// } else {
// Toast.makeText(context, "FAilure "+e.toString(), Toast.LENGTH_SHORT).show();
//
// Log.d("ANNOUNCEMENT","FAILURE"+e.toString());
// }
// }

    @Override
    public void done(String result, com.parse.ParseException e) {
        // TODO Auto-generated method stub
           if (e == null) {
            Toast.makeText(context, "HEHE", Toast.LENGTH_SHORT).show();
            Log.d("ANNOUNCEMENT" ,"SUCCESS");
         } else {
            Toast.makeText(context, "FAilure "+e.toString(), Toast.LENGTH_SHORT).show();

             Log.d("ANNOUNCEMENT","FAILURE"+e.toString());
         }
    }
  });

}
//////Errorr

FAILUREcom.parse.ParseRequest$ParseRequestException: {"code":115,"message":"Channels and query should be set at least one."}

Most helpful comment

What is the way of using it with " querying with array"?

All 31 comments

use 'where'.
....
query : query -> where : query
....
see this document : https://parse.com/docs/js/guide#push-notifications

Elaborate plz!!!!!!

... Parse.Push.send({ query: query, data: { alert: msg, sound: 'default' } } ....
to
... Parse.Push.send({ where: query, data: { alert: msg, sound: 'default' } } ....

Thank you for the previous query....it almost worked...:)
If I want to send push to multiple users ...Is that possible?

It has to ways : use ParsePromise, or use querying with array.

If you want to use Promise, you will send different message(maybe).
-> reference is here : https://parse.com/docs/js/guide#promises-promises-in-parallel

This reference use '_' (underscore), parse server is not support.

replace for each.

What is the way of using it with " querying with array"?

Oops. It's not supported that. Sorry.

Using promise is best solution, for now (or for me).

Okay...thanks .. I ll try to configure it and come back with the problems...:)
Can I send push to multiple channels as well ?

I'm not sure, cause I'm not use channel yet.

But using channel is more easier to send people same message.

ok thanks for helping me out

Sir i changed this
... Parse.Push.send({ query: query, data: { alert: msg, sound: 'default' } } ....
to
... Parse.Push.send({ where: query, data: { alert: msg, sound: 'default' } } ....
......but in _pushstatus it is showing running (status)

logs

{
"_id" : ObjectId("5703a8a90ac1a5882c3b4008"),
"objectId" : "di4FL8PPCv",
"pushTime" : "2016-04-05T11:59:37.354Z",
"_created_at" : ISODate("2016-04-05T11:59:37.354+0000"),
"query" : "{\"userId\":\"4tKMN1HctW\"}",
"payload" : {
"alert" : "5",
"sound" : "default"
},
"source" : "rest",
"title" : null,
"expiry" : null,
"status" : "running",
"numSent" : NumberInt(0),
"pushHash" : "6e4b2efabbfd5b883b9baf5ac78faf5b",
"_wperm" : [

], 
"_rperm" : [

]

}

The push status never gets updated?

yes it never gets updated

can you run with VERBOSE=1? what version of parse-server are you running, since 2.2.5 (released yesterday) we improved the tracking of push errors and reporting

can u tell in detail how to do that

update or set an environment variable? for the update, just run npm update parse-server for the environment, given you're on mac or linux that would be VERBOSE=1 (your command to start parse-server)

can u please provide me an example link i am not gettign what are u saying

i have updated it but it does not change anything

can you please provide the logs when running with VERBOSE=1?

i ran parse server using command "npm start " where i have to use verbose=1

run: VERBOSE=1 npm start

ok

here is the verbose ...

verbose: POST /parse/push { 'user-agent': 'node-XMLHttpRequest, Parse/js1.8.1 (NodeJS 5.3.0)',
accept: '_/_',
'content-type': 'text/plain',
host: '166.62.82.202:1337',
'content-length': '276',
connection: 'close' } {
"where": {
"userId": "5ZMHufuKzr"
},
"data": {
"alert": "Hello",
"sound": "default"
}
}
verbose: {
"response": {
"result": true
}
}
success
verbose: {
"response": {
"result": "Push sent "
}
}
verbose: sending push to 0 installations
verbose: sent push! 0 success, 0 failures

Seems that your query is malformed as verbose: sending push to 0 installations indicates

here is my cloud code

untitledmmkmk

Does your query returns installations? I don't think so, given the logs...
Again, the github issues are not a support channel for debugging your code. Please ask over stackoverflow

where is the error can u elaborate

@Heman6886 ask over http://stackoverflow.com/ please as this is an implementation issue on your side and not an issue on parse-server. Thanks.

Was this page helpful?
0 / 5 - 0 ratings