by
3 6

Send a push notification in node with OneSignal

Send a push notification in node with OneSignal : 
onesignal-node.js
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1073013/Send-a-push-notification-in-node-with-On?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
var request = require('request'); var sendMessage = function(user, message){ var restKey = '****'; var appID = '****'; request( { method:'POST', uri:'https://onesignal.com/api/v1/notifications', headers: { "authorization": "Basic "+restKey, "content-type": "application/json" }, json: true, body:{ 'app_id': appID, 'contents': {en: message}, 'include_player_ids': [user] } }, function(error, response, body) { if(!body.errors){ console.log(body); }else{ console.error('Error:', body.errors); } } ); } sendMessage('a9fb63b1-b5cc-4ee9-92f0-5be15eb300c0', 'Hello!');
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus