forked from Bandwidth/node-numbers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
subscription_list_and_delete.js
45 lines (41 loc) · 1.37 KB
/
subscription_list_and_delete.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const numbers = require("@bandwidth/numbers");
//Using client directly
const client = new numbers.Client(process.env.BANDWIDTH_ACCOUNT_ID,
process.env.BANDWIDTH_API_USER,
process.env.BANDWIDTH_API_PASSWORD);
const findAndDeleteSubscriptionById = async (id) => {
try {
const subscriptions = await numbers.Subscription.listAsync(client, {});
for (const s of subscriptions) {
console.log(s.id);
// 6be53e36-...-668ee3603d71
// b57094d3-...-25085d224b48
if (s.id === id) {
const deletedS = await s.deleteAsync();
console.log(deletedS);
// {}
}
}
const moreSubscriptions = await numbers.Subscription.listAsync(client, {});
console.log(moreSubscriptions)
// [
// Subscription {
// subscriptionId: '6be53e36-...-668ee3603d71',
// orderType: 'portins',
// emailSubscription: { email: '[email protected]', digestRequested: 'NONE' },
// client: Client {
// prepareRequest: [Function],
// concatAccountPath: [Function],
// prepareUrl: [Function],
// xml2jsParserOptions: [Object]
// },
// id: '6be53e36-...-668ee3603d71'
// }
// ]
}
catch (e) {
console.log('Error');
console.log(e);
}
}
findAndDeleteSubscriptionById('b57094d3-...-25085d224b48');