Page 1 of 1

callback node js

Posted: 29. Apr 2022, 16:09
by ubicar
First of all congratulations for this powerful service & app!

I have setup the callback url to our node js backend service. After a send notification the url is called but with empty data:

/pushsafer callback req.body: {}
/pushsafer callback req.params: {}
/pushsafer callback req.query: {}

while I was expecting req.body.json to be like:

{
"status":1,
"success":"message transmitted",
"available":1823,
"message_ids":"1324312:118,1324313:324"
}

Am I missing something?

Thank you.

Regards.
Denis

Re: callback node js

Posted: 29. Apr 2022, 19:00
by admin
Hi Denis,

the data you will find in POST parameter json

https://www.pushsafer.com/en/pushapi#api-callback

Kevin

Re: callback node js

Posted: 3. May 2022, 09:24
by ubicar
Thank you for your message Kevin.

Unfortunately, it looks like there is no json parameter in the POST request. (req.body is empty)

Best regards.
Denis

Re: callback node js

Posted: 3. May 2022, 09:51
by admin
Just tested (with PHP), works as it should

Response

Code: Select all

{"status":1,"success":"message transmitted","available":22159,"message_ids":"22369782:119"}
Kevin

Re: callback node js

Posted: 3. May 2022, 10:17
by ubicar
For information, as the request body is a multipart message, bodyParser package does not handle the post parameter. multer package is needed.

var multer = require('multer');
var forms = multer();
app.use(forms.array());

finally, in the post route, the req.body is fine:

/pushsafer callback req.body: {"json":"{"status":1,"success":"message transmitted","available":982,"message_ids":"22371903:52962"}"}

best regards.
Denis

Re: callback node js

Posted: 3. May 2022, 19:05
by admin
thanks for sharing!

Kevin