I have written a function in Firebase cloud functions to make a HTTP Post to the Onesignal API. I first test my request in Postman and ensured that the body and headers are correct and working - it succeeded. I then proceeded to create a post request using the request npm package. This is what I have so far
exports.addMessage = functions.https.onRequest((req, res) => {
const Requestbody = {
included_segments: ['Subscribed Users'],
app_id: 'XXXXXXXXXX',
contents: { 'en': 'Test Notification Body' },
headings: { 'en': 'Test Title' }
}
httpRequest.post({
url: 'https://onesignal.com/api/v1/notifications',
headers: {
'Authorization': 'Some Token...',
'Content-Type': 'application/json'
},
body: JSON.stringify(Requestbody)
},
function (error, response, body) {
if (error) { return res.status(500).send('Failed - ' + JSON.stringify(error)); }
console.log('Onesignal Response: ' + JSON.stringify(response));
return res.status(200).send('Success');
});
}
Every time I invoke this cloud function, the request.post call returns the following Error:
getaddrinfo ENOTFOUND onesignal.com onesignal.com:443
But that URL I provided is the exact one I use to test within Post Man.