Skip to content

Push Notifications - working via REST, not via cloud code #3022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ethandrower opened this issue Nov 5, 2016 · 10 comments
Closed

Push Notifications - working via REST, not via cloud code #3022

ethandrower opened this issue Nov 5, 2016 · 10 comments

Comments

@ethandrower
Copy link

#Describe your issue in as much detail as possible.

I’m running parse-server on ubuntu and can't seem to get push notifications working when sent in cloud code, even though they are succeeding in the logs.

Pushes work (and are received by the devices ) when using a REST api call (passing master key) but don't work when cloud code calls them. This is what leads me to believe I am having a parse problem vs. an apple/iOS problem.

What's interesting is that the cloud code Parse.Push() method returns a success and thus no error message. In verbose logging, you can even see the connections initiated with the correct deviceIDs

Here is my cloud function, the success callback in cloud is always called(unless I deliberately make the serverURL variable something incorrect). Pushes are just never delivered to the devices.

Parse.Push.send(
{
// where: pushQueryClient,
channels: ["user_tkP7gurGzc"], //this is a specific user who is subscribed to this channel.
data:
{
alert: pushTextClient
}
},
{
success:function(){
console.log("push sent");
},
error: function(error){
console.log("push failed");
console.dir(error);
},

useMasterKey: true});

Here are the verbose logs showing the push being sent successfully
verbose: REQUEST for [POST] /parse/push: {
"channels": [
"user_tkP7gurGzc"
],
"data": {
"alert": ""
}
} method=POST, url=/parse/push, user-agent=node-XMLHttpRequest, Parse/js1.9.2 (NodeJS 4.5.0), accept=/, content-type=text/plain, host=localhost:1337, content-length=252, connection=close, channels=[user_tkP7gurGzc], alert=
verbose: REQUEST for [POST] /parse/push: {
"channels": [
"user_HFxoncoHal"
],
"data": {
"alert": ""
}
} method=POST, url=/parse/push, user-agent=node-XMLHttpRequest, Parse/js1.9.2 (NodeJS 4.5.0), accept=/, content-type=text/plain, host=localhost:1337, content-length=252, connection=close, channels=[user_HFxoncoHal], alert=
verbose: RESPONSE from [POST] /parse/push: {
"headers": {
"X-Parse-Push-Status-Id": "6JmxBBF6Ws"
},
"response": {
"result": true
}
} X-Parse-Push-Status-Id=6JmxBBF6Ws, result=true
verbose: RESPONSE from [POST] /parse/push: {
"headers": {
"X-Parse-Push-Status-Id": "MsDOblnESX"
},
"response": {
"result": true
}
} X-Parse-Push-Status-Id=MsDOblnESX, result=true
verbose: sending push to 2 installations
verbose: sending push to 1 installations

verb parse-server-push-adapter APNS APNS Connection 0 Connected
verb parse-server-push-adapter APNS APNS Connection 0 Notification transmitted to e2c1bf254f2d855a475733fb9dcec0cf359a864ae6b8c5d1812832d9b51f6831
verb parse-server-push-adapter APNS APNS Connection 0 Notification transmitted to 8d9d36819a129251452b1a8ae722d2c8ae43e4c0864498e4983081f50cdd1f88
verbose: sent push! 2 success, 0 failures
verb parse-server-push-adapter APNS APNS Connection 0 Notification transmitted to ae7ff32c8df269b65819941338c83a2a94d73cb0ac8efbaf37cea4c0fad14f56
verbose: sent push! 1 success, 0 failures

Here is the curl that works along with corresponding verbose logs:

curl -X POST -H "X-Parse-Application-Id: myappid" -H "X-Parse-Master-Key: mymaster" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{
"channels": ["user_tkP7gurGzc"],
"data": {
"alert": "work!"
}
}' "http://mydomainname.com:1337/parse/push"

Here are the verbose logs when I use the rest api to send a push

verbose: REQUEST for [POST] /parse/push: {
"channels": [
"user_tkP7gurGzc"
],
"data": {
"alert": "work!"
}
} method=POST, url=/parse/push, host=myhost.com:1337, connection=keep-alive, content-length=76, origin=chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop, postman-token=11fdced1-045e-3953-d71d-60e0567dd7e6, cache-control=no-cache, x-parse-master-key=masterkey, x-parse-application-id=appid, user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36, content-type=application/json, accept=/, accept-encoding=gzip, deflate, accept-language=en-US,en;q=0.8, channels=[user_tkP7gurGzc], alert=work!
verbose: RESPONSE from [POST] /parse/push: {
"headers": {
"X-Parse-Push-Status-Id": "2SNIe7Eiba"
},
"response": {
"result": true
}
} X-Parse-Push-Status-Id=2SNIe7Eiba, result=true
verbose: sending push to 2 installations
verb parse-server-push-adapter APNS APNS Connection 0 Notification transmitted to e2c1bf254f2d855a475733fb9dcec0cf359a864ae6b8c5d1812832d9b51f6831
verb parse-server-push-adapter APNS APNS Connection 0 Notification transmitted to 8d9d36819a129251452b1a8ae722d2c8ae43e4c0864498e4983081f50cdd1f88
verbose: sent push! 2 success, 0 failures

Steps to reproduce

This occurs when cloud code is executed (on an afterSave trigger), and the success function defined above is called.

Expected Results

With the success function being called, I'd expect the notifications to be sent to the device, especially since push's sent via a REST call to parse work and are received on the devices.

Actual Outcome

No errors in parse logs, no notifications received by devices.

I guess my real question at this point: Are push notifications sent differently if the call is initiated from cloud code vs. the REST api?

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 2.15.9
      I realize this is not the most up to date according the versions doc, but it is the highest upgrade available via npm update.
    • Operating System: "Ubuntu 14.04.5 LTS"
    • Hardware: Digital Ocean, middle tier VM
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): localhost
  • Database

    • MongoDB version: 3.0.12
    • Storage engine: "name" : "mmapv1"
    • Hardware: run locally on same Digital Ocean VM
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): localhost
@turkenh
Copy link

turkenh commented Dec 6, 2016

Why this issue closed? I hit exactly same issue, how did you solve this?

@shagul298
Copy link

I hit exactly same issue too... pls help me to solve this issue..

@ethandrower ethandrower reopened this Dec 9, 2016
@rawatshailender
Copy link

Please check there are no Client Keys / Javascript keys in your Parse Server initialization script.
Update Parse Server to 2.2.24
Update NodeJS to atleast > 4.5

@vsouza
Copy link

vsouza commented Jan 10, 2017

I have updated Parse Server, and updated NodeJS. Same error here 😢

@lfarah
Copy link

lfarah commented Jan 10, 2017

@drew-gross Can you help us out?

@ethandrower
Copy link
Author

One thing that tripped me up earlier, was that you need to make sure your push certs with Apple are working properly. If you're in development still make sure each individual device is registered, and added to an ad-hoc provisioning certificate. When there was a problem with my cert, I saw delivery successes in the parse log but never got any on the device.

@stale
Copy link

stale bot commented Sep 18, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 18, 2018
@stale stale bot closed this as completed Sep 25, 2018
@nareninindia
Copy link

nareninindia commented Sep 28, 2018

Parse.Cloud.define('sendPostPushNotification', (req) => { Parse.Push.send({ where: { "deviceType": { "$in": [ "android" ] } }, data: { alert: "sample alert", title: "sample title" // Sending Uri will help mobile app. } }, { useMasterKey: true }) .then(function() { // Push sent! return 'Push sent!'; }, function(error) { // There was a problem :( return 'There was a problem while sending push!'; }); });
The above which is done as per https://docs.parseplatform.org/parse-server/guide/#4-send-push-notifications is not sending push notifications. But using rest api via curl, push notifications are happening.

When I first start the server, I am getting this message: WARNING, Unable to connect to 'https://127.0.0.1:1337/parse'. Cloud code and push notifications may be unavailable!

When I send push notification using above method, I am getting this error message: 'XMLHttpRequest failed: "Unable to connect to the Parse API"'

Did anyone face this issue, or can anyone help me with this?

@georgesjamous
Copy link
Contributor

@nareninindia this is not a notification issue.
I am guessing that you are running parse locally without https.
Change the URL to "http".
If it still doesn't work, provide your full server initialization code.

@nareninindia
Copy link

@georgesjamous Thank you. Your comment helped me resolve the issue. Problem is with initialisation.
With Nginx, I was pointing the URL to local machine. I changed serverUrl to https://my.domain.name/parse and it started working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants