Hello, I'm trying to implement the OneSignal API on my toolbar, and I'm wondering if it is possible to make an external API call inside the express server.
Here is an example:
var sendNotification = function(data) { var headers = { "Content-Type": "application/json; charset=utf-8", "Authorization": "Basic NGEwMGZmMjItY2NkNy0xMWUzLTk5ZDUtMDAwYzI5NDBlNjJj" }; var options = { host: "onesignal.com", port: 443, path: "/api/v1/notifications", method: "POST", headers: headers }; var https = require('https'); var req = https.request(options, function(res) { res.on('data', function(data) { console.log("Response:"); console.log(JSON.parse(data)); }); }); req.on('error', function(e) { console.log("ERROR:"); console.log(e); }); req.write(JSON.stringify(data)); req.end(); };
Here is the application route
app.post('/path', function(req, res){ var message = { app_id: "5eb5a37e-b458-11e3-ac11-000c2940e62c", contents: {"en": "English Message"}, included_segments: ["All"] }; sendNotification(message); });
Thanks!
source share