Repository navigation
Parse Server Push giving APNS 513 #697
Copy link
Copy link
Closed
Description
Hi all,
I'm getting an issue when trying to send push notifications over Parse Server using cloud code, specifically, the heroku server is spitting a 513 APNS at me. This was triggered by calling the cloud function on the iOS client-side.
I've discluded my keys and urls, etc, so they are in ALL_CAPS.
What do I need to do to make Push notification work on my parse server? Is there an issue with my .p12?
Here is my cloud function:
Parse.Cloud.define('test', function(req, res) {
Parse.Push.send({
channels: ['global'],
data: {
alert: 'Test',
badge: 1,
sound: 'default'
}
}, {
success: function() {
console.log('##### PUSH OK');
},
error: function(error) {
console.log('##### PUSH ERROR' + error.message);
},
useMasterKey: true
});
});
Here is my Index.js setup:
var express = require('express');
var ParseServer = require('parse-server').ParseServer;
var databaseUri = process.env.DATABASE_URI || process.env.MONGOLAB_URI;
if (!databaseUri) {
console.log('DATABASE_URI not specified, falling back to localhost.');
}
var api = new ParseServer({
databaseURI: databaseUri || 'mongodb://localhost:27017/dev',
cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
appId: process.env.APP_ID || 'APP_ID',
masterKey: process.env.MASTER_KEY || 'MATER_KEY', //Add your master key here. Keep it secret!
clientKey: 'CLIENT_KEY',
serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
push:{
ios: {
pdx: '/Users/AlecKriebel/Desktop/ParsePush.p12', // the path and filename to the .p12 file you exported earlier.
bundleId: 'BUNDLE-ID',
production: false
}
}
});
// Client-keys like the javascript key or the .NET key are not necessary with parse-server
// If you wish you require them, you can set them as options in the initialization above:
// javascriptKey, restAPIKey, dotNetKey, clientKey
var app = express();
// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';
app.use(mountPath, api);
// Parse Server plays nicely with the rest of your web routes
app.get('/', function(req, res) {
res.status(200).send('I dream of being a web site.');
});
var port = process.env.PORT || 1337;
app.listen(port, function() {
console.log('parse-server-example running on port ' + port + '.');
});
Here is the server response:
2016-02-27T09:21:13.320224+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response" method=POST path="/parse/functions/test" host=SERVER_URL request_id=e35a7606-e3e5-4303-a546-b6b604466f01 fwd="174.77.32.122" dyno=web.1 connect=1ms service=637ms status=503 bytes=0
2016-02-27T09:21:13.220879+00:00 app[web.1]: ##### PUSH OK
2016-02-27T09:21:13.322808+00:00 app[web.1]: sound: 'default',
2016-02-27T09:21:13.322811+00:00 app[web.1]: category: undefined } },
2016-02-27T09:21:13.322799+00:00 app[web.1]: APNS Notification caused error: 513 for device Device {
2016-02-27T09:21:13.322803+00:00 app[web.1]: token: <Buffer bf 90 0f e6 c5 85 85 cb 32 b8 d1 73 65 ce e8 61 3a 13 2d 98 be 3f 1d 50 14 68 a6 f9 c6 0d 68 95>,
2016-02-27T09:21:13.322804+00:00 app[web.1]: connIndex: 0,
2016-02-27T09:21:13.322809+00:00 app[web.1]: alert: 'Test',
2016-02-27T09:21:13.322810+00:00 app[web.1]: 'url-args': undefined,
2016-02-27T09:21:13.322806+00:00 app[web.1]: appIdentifier: 'BUNDLE-ID' } { encoding: 'utf8',
2016-02-27T09:21:13.322806+00:00 app[web.1]: payload:
2016-02-27T09:21:13.322808+00:00 app[web.1]: { badge: 1,
2016-02-27T09:21:13.322814+00:00 app[web.1]: compiled: '{"aps":{"badge":1,"sound":"default","alert":"Test"}}',
2016-02-27T09:21:13.322807+00:00 app[web.1]: { aps:
2016-02-27T09:21:13.323511+00:00 app[web.1]: APNS can not find vaild connection for {"type":"Buffer","data":[191,144,15,230,197,133,133,203,50,184,209,115,101,206,232,97,58,19,45,152,190,63,29,80,20,104,166,249,198,13,104,149]}
2016-02-27T09:21:13.322812+00:00 app[web.1]: expiry: undefined,
2016-02-27T09:21:13.322815+00:00 app[web.1]: truncateAtWordEnd: false,
2016-02-27T09:21:13.322812+00:00 app[web.1]: priority: 10,
2016-02-27T09:21:13.353632+00:00 app[web.1]: npm ERR! argv "/app/.heroku/node/bin/node" "/app/.heroku/node/bin/npm" "start"
2016-02-27T09:21:13.354248+00:00 app[web.1]: npm ERR! npm v3.6.0
2016-02-27T09:21:13.322813+00:00 app[web.1]: retryLimit: -1,
2016-02-27T09:21:13.353835+00:00 app[web.1]: npm ERR! node v5.6.0
2016-02-27T09:21:13.322813+00:00 app[web.1]: device: undefined,
2016-02-27T09:21:13.353332+00:00 app[web.1]: npm ERR! Linux 3.13.0-77-generic
2016-02-27T09:21:13.355041+00:00 app[web.1]: npm ERR! Exit status 1
2016-02-27T09:21:13.322817+00:00 app[web.1]: _sound: 'default' }
2016-02-27T09:21:13.355376+00:00 app[web.1]: npm ERR! Failed at the [email protected] start script 'node index.js'.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
jaydeep82 commentedon Mar 3, 2016
@AlecKriebel
It seems like issue with .p12 files. You need to create p12 files without password and use it here.
Please let me know if you still have same error.
AlecKriebel commentedon Mar 3, 2016
@jaydeep82 I've been using .p12 files without passwords.
I've even tried including both a development AND production .p12 and it has not worked.
It is worth noting that I have the exact same .p12 in Parse and push notifications work there, but not in my Heroku/MongoDB parse-server.
jaydeep82 commentedon Mar 4, 2016
@AlecKriebel
Did you also push the .p12 files in heroku using git command ? I think node.js could not find the p12 file in specified location.
For me, I have keep MyParsePush.p12 at same location of index.js.
Please let me know if you still have same error.
AlecKriebel commentedon Mar 4, 2016
@jaydeep82
After I posted this, I changed it to be that. My Index.js is now:
And here is the git directory that has been pushed:

With this config it still does not work. Do you think I should remove the
__dirnamebefore the file in my index.js?jaydeep82 commentedon Mar 4, 2016
@AlecKriebel
Yes, please remove the _dirname and use as below :
I've removed '/' also.
Then push the change to heroku using git and check again.
Hope this will work.
AlecKriebel commentedon Mar 4, 2016
@jaydeep82
This still does not work after making this change.
Index.js:
Pushed git directory:

flovilmart commentedon Mar 5, 2016
node-apn/node-apn#123
AlecKriebel commentedon Mar 5, 2016
@flovilmart Thanks, that gets me in the right direction, however, this error is still unclear
As I understand, to authenticate push services a .p12 or a key and cert file in the .cem format is needed. Since I've supplied a .p12, why would the error be that I need a .pem file?
I apologize if this is obvious but, from what I can see, the index.js file is only 262 lines, not 288 or more.
flovilmart commentedon Mar 6, 2016
Provide the full path of your certificate, that will help. path.resolve(__dirname, certPath) where certPath is the relative path to the certificate from the file you're calling it.
liennh commentedon Mar 10, 2016
if you host your own Parse Server on Heroku or AWS, The PFPush is NOT supported. (Said by Parse.com)
AlecKriebel commentedon Mar 10, 2016
@liennh Hmmm... I had seen that somewhere, but later heard support had been added. I dont see it on here, do you have a link? Any 3rd party push recommendations?
liennh commentedon Mar 10, 2016
@AlecKriebel You are right. Push feature has been added in Parse Server. Perhap your problem is at generating PEM or .P12 file.
I remember that before Parse.com recommended developers to use the Push provider https://onesignal.com/
pbush25 commentedon Mar 13, 2016
I am having the exact same error as @AlecKriebel was. We discussed earlier today, and he had still not come to a resolution for this problem. Between talking to him and using what was here, I attempted to use APNS by setting my environment variables to this:
With this in my
index.jsfile, I run into the same errors, where Heroku logs say2016-03-13T03:31:45.778187+00:00 app[web.1]: /app/node_modules/parse-server/lib/index.js:2882016-03-13T03:31:45.778279+00:00 app[web.1]: ^2016-03-13T03:31:45.778313+00:00 app[web.1]: Error: ENOENT: no such file or directory, open 'cert.pem'I spent several hours troubleshooting today but was unable to come to a resolution. I redownloaded my certificates and reexported them too just to make sure, but these were the same I was using on Parse before and they worked without issue. Since two people have run into the same error, this seems like something that needs to be addressed.
flovilmart commentedon Mar 13, 2016
the key is pfx not pdx
pbush25 commentedon Mar 13, 2016
Wow I'm an idiot. One letter! Thanks @flovilmart!
2 remaining items
AlecKriebel commentedon Mar 13, 2016
@pbush25 @flovilmart I'll be willing to bet that was my issue too, testing now. If it is, I'll probably rip my hair out. Will close after I test.
pbush25 commentedon Mar 13, 2016
Oh believe me, I wanted to rip my hair out too!
flovilmart commentedon Mar 13, 2016
Is there a typo in the docs?
Just FYI, we're working on upgrading to the new API for APNS over HTTP 2, where a single certificate would work for both dev and production
pbush25 commentedon Mar 13, 2016
I don't see a typo in the the main push docs, but they might be somewhere seeing as two people managed to end up with it.
AlecKriebel commentedon Mar 13, 2016
@flovilmart From what I remember, I definitely copied and pasted the initialization code from somewhere, probably the docs at one point.
I know I had been following this setup guide: http://rogerstringer.com/2016/02/11/parse-server-push/
which also uses 'pdx'
flovilmart commentedon Mar 13, 2016
looking at our docs: https://github.com/ParsePlatform/parse-server/wiki/Push we properly describe with pfx :)
And I can see there are many errors in that tutorial, missing / at the end of the URL for the Android SDK etc...
pbush25 commentedon Mar 13, 2016
Can you clarify for me that using this new version of Parse Push we can no longer send pushes from a client such as the iOS SDK?
flovilmart commentedon Mar 13, 2016
no, that don,t change the client push sending abilities, for now it's disabled
pbush25 commentedon Mar 13, 2016
So all pushes will have to be set through cloud code now?
flovilmart commentedon Mar 13, 2016
yes that's right
pbush25 commentedon Mar 13, 2016
Does that include from the PHP SDK also?
flovilmart commentedon Mar 15, 2016
you can send them from any SDK with masterKey access