DockerERTFF/extensions/server_connect/modules/onesignal_delete_template.js

27 lines
1.1 KiB
JavaScript

// JavaScript Document
exports.onesignal_delete_template = async function (options) {
// get appid
const appid = this.parseOptional(options.appid, '*', process.env.ONESIGNAL_APP_ID)
console.log(options.appid + " => " + appid)
const template_id = this.parseRequired(options.template_id, '*', 'Template ID not specified')
console.log('Template_id: ' + options.template_id + " => " + template_id)
const fetch = require('node-fetch');
const url = `https://api.onesignal.com/templates/${template_id}?app=id=${appid}`;
const os_options = { method: 'DELETE', headers: { accept: 'application/json', Authorization: `Basic ${process.env.ONESIGNAL_REST_API_KEY}` } };
return fetch(url, os_options)
.then(res => {
if (!res.ok) {
throw new Error(`HTTP error! status: ${res.status}`);
}
return res.json().then(json => {
json.status = res.status; // Add status to json response
return json;
});
})
.catch(err => console.error('Error:', err));
}