31 lines
1.0 KiB
JavaScript
31 lines
1.0 KiB
JavaScript
// JavaScript Document
|
|
// v1.0.0
|
|
exports.onesignal_delete_segment = async function (options) {
|
|
// get appid
|
|
const appid = this.parseOptional(options.appid, '*', process.env.ONESIGNAL_APP_ID)
|
|
console.log(options.appid + " => " + appid)
|
|
|
|
const segment_id = this.parseRequired(options.segment_id, '*', 'Segment ID missing')
|
|
console.log(options.segment_id + " => " + segment_id)
|
|
const fetch = require('node-fetch')
|
|
const url = `https://api.onesignal.com/apps/${appid}/segments/${segment_id}`
|
|
const os_options = {
|
|
method: 'DELETE',
|
|
headers: {
|
|
accept: 'application/json',
|
|
Authorization: `Basic ${process.env.ONESIGNAL_REST_API_KEY}`
|
|
}
|
|
}
|
|
console.log(os_options)
|
|
return fetch(url, os_options)
|
|
.then(res => {
|
|
|
|
return res.json().then(json => {
|
|
json.status = res.status; // Add status to json response
|
|
return json;
|
|
});
|
|
})
|
|
.catch(err => console.error('Error:', err));
|
|
}
|
|
|