Added API method to delete subscribers
This commit is contained in:
parent
eab46d758a
commit
c72f03ff5e
4 changed files with 125 additions and 1 deletions
|
@ -531,6 +531,34 @@ module.exports.getById = (listId, id, callback) => {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports.getByEmail = (listId, email, callback) => {
|
||||||
|
if (!email) {
|
||||||
|
return callback(new Error('Missing Subbscription email address'));
|
||||||
|
}
|
||||||
|
|
||||||
|
db.getConnection((err, connection) => {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
connection.query('SELECT * FROM `subscription__' + listId + '` WHERE email=?', [email], (err, rows) => {
|
||||||
|
connection.release();
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!rows || !rows.length) {
|
||||||
|
return callback(null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
let subscription = tools.convertKeys(rows[0]);
|
||||||
|
// ensure list id in response
|
||||||
|
subscription.list = subscription.list || listId;
|
||||||
|
return callback(null, subscription);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
module.exports.getWithMergeTags = (listId, cid, callback) => {
|
module.exports.getWithMergeTags = (listId, cid, callback) => {
|
||||||
module.exports.get(listId, cid, (err, subscription) => {
|
module.exports.get(listId, cid, (err, subscription) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -207,4 +207,73 @@ router.post('/unsubscribe/:listId', (req, res) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.post('/delete/:listId', (req, res) => {
|
||||||
|
let input = {};
|
||||||
|
Object.keys(req.body).forEach(key => {
|
||||||
|
input[(key || '').toString().trim().toUpperCase()] = (req.body[key] || '').toString().trim();
|
||||||
|
});
|
||||||
|
lists.getByCid(req.params.listId, (err, list) => {
|
||||||
|
if (err) {
|
||||||
|
res.status(500);
|
||||||
|
return res.json({
|
||||||
|
error: err.message || err,
|
||||||
|
data: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!list) {
|
||||||
|
res.status(404);
|
||||||
|
return res.json({
|
||||||
|
error: 'Selected listId not found',
|
||||||
|
data: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!input.EMAIL) {
|
||||||
|
res.status(400);
|
||||||
|
return res.json({
|
||||||
|
error: 'Missing EMAIL',
|
||||||
|
data: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
subscriptions.getByEmail(list.id, input.EMAIL, (err, subscription) => {
|
||||||
|
if (err) {
|
||||||
|
res.status(500);
|
||||||
|
return res.json({
|
||||||
|
error: err.message || err,
|
||||||
|
data: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!subscription) {
|
||||||
|
res.status(404);
|
||||||
|
return res.json({
|
||||||
|
error: 'Subscription not found',
|
||||||
|
data: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
subscriptions.delete(list.id, subscription.cid, (err, subscription) => {
|
||||||
|
if (err) {
|
||||||
|
res.status(500);
|
||||||
|
return res.json({
|
||||||
|
error: err.message || err,
|
||||||
|
data: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!subscription) {
|
||||||
|
res.status(404);
|
||||||
|
return res.json({
|
||||||
|
error: 'Subscription not found',
|
||||||
|
data: []
|
||||||
|
});
|
||||||
|
}
|
||||||
|
res.status(200);
|
||||||
|
res.json({
|
||||||
|
data: {
|
||||||
|
id: subscription.id,
|
||||||
|
deleted: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<ol class="breadcrumb">
|
<ol class="breadcrumb">
|
||||||
<li><a href="/">Home</a></li>
|
<li><a href="/">Home</a></li>
|
||||||
<li class="active">Automation Triggers</li>
|
<li><a href="/triggers">Automation Triggers</a></li>
|
||||||
<li class="active">Triggered {{name}}</li>
|
<li class="active">Triggered {{name}}</li>
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
|
|
|
@ -113,3 +113,30 @@
|
||||||
|
|
||||||
<pre>curl -XPOST {{serviceUrl}}api/unsubscribe/B16uVTdW?access_token={{accessToken}}\
|
<pre>curl -XPOST {{serviceUrl}}api/unsubscribe/B16uVTdW?access_token={{accessToken}}\
|
||||||
--data 'EMAIL=test@example.com'</pre>
|
--data 'EMAIL=test@example.com'</pre>
|
||||||
|
|
||||||
|
<h3>POST /api/delete/:listId – Delete subscription</h3>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This API call deletes a subscription
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>GET</strong> arguments
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li><strong>access_token</strong> – your personal access token
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>POST</strong> arguments
|
||||||
|
</p>
|
||||||
|
<ul>
|
||||||
|
<li><strong>EMAIL</strong> – subscriber's email address (<em>required</em>)
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<strong>Example</strong>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<pre>curl -XPOST {{serviceUrl}}api/delete/B16uVTdW?access_token={{accessToken}}\
|
||||||
|
--data 'EMAIL=test@example.com'</pre>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue