Skip to content

Instantly share code, notes, and snippets.

@abarisain
Last active December 5, 2018 23:45
Show Gist options
  • Save abarisain/8f1747a2ed92c88ad7e5a027fb651f42 to your computer and use it in GitHub Desktop.
Save abarisain/8f1747a2ed92c88ad7e5a027fb651f42 to your computer and use it in GitHub Desktop.
var https = require('https');
let DEBUG = true;
let customPayload = {};
let requestOptions = {
"hostname": "api.batch.com",
"port": 443,
"method": "POST",
"path": "/1.0/" + "<your app api key>" + "/transactional/send",
"headers": {
"Content-Type": "application/json",
"User-Agent": "BatchPushSender 1.0",
"X-Authorization": "rest key"
}
};
let apiPayload = {
"group_id": "batch_push_sender",
"push_time": "now",
"message": {
"body": "<your message body here>"
},
"recipients": {
"tokens": ["<token>"]
},
"sandbox": false, // Only for iOS
"deeplink": "http://google.fr",
"custom_payload": JSON.stringify(customPayload)
};
let request = https.request(requestOptions, (res) => {
let data = "";
res.setEncoding("utf8");
res.on("data", (chunk) => {
data += chunk;
});
res.on("end", (chunk) => {
if (DEBUG) {
console.log("[BatchPushSender] Batch API Request response: %j", data);
}
});
});
request.on("error", (e) => {
if (DEBUG) {
console.log("[BatchPushSender] Batch API Request error: %j", e);
}
});
request.write(JSON.stringify(apiPayload));
request.end();
@wisemasterwizz
Copy link

Line 55 should read 'request.write(JSON.stringify(apiPayload));'

As it's missing the ')'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment