Skip to content

Commit fcda7ef

Browse files
author
Dan Tolbert
committed
Fixed Subscription List functionality
1 parent 80e39c9 commit fcda7ef

File tree

4 files changed

+53
-7
lines changed

4 files changed

+53
-7
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ This SDK stable for node versions 7 and above
1515
| > 7 | | Supported |
1616

1717
## Release Notes
18-
| Version | Notes |
19-
|:--------|:---------------------------------------------------------------------|
20-
| 1.1.0 | Added import tn functionality, added promise based `Async` functions |
21-
| 1.2.0 | Added CSR lookup functionality |
18+
| Version | Notes | |
19+
|:--------|:------------------------------------------------------------------------------------------------------------------------------------------|:---|
20+
| 1.1.0 | Added import tn functionality, added promise based `Async` functions | |
21+
| 1.2.0 | Added CSR lookup functionality | . |
22+
| 1.2.1 | Fixed Subscription List functionality. Example code at: [examples/subscription_list_and_delete](examples/subscription_list_and_delete.js) | |
2223

2324

2425
## Install
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const numbers = require("@bandwidth/numbers");
2+
3+
//Using client directly
4+
const client = new numbers.Client(process.env.BANDWIDTH_ACCOUNT_ID,
5+
process.env.BANDWIDTH_API_USER,
6+
process.env.BANDWIDTH_API_PASSWORD);
7+
8+
9+
const findAndDeleteSubscriptionById = async (id) => {
10+
try {
11+
const subscriptions = await numbers.Subscription.listAsync(client, {});
12+
for (const s of subscriptions) {
13+
console.log(s.id);
14+
// 6be53e36-...-668ee3603d71
15+
// b57094d3-...-25085d224b48
16+
if (s.id === id) {
17+
const deletedS = await s.deleteAsync();
18+
console.log(deletedS);
19+
// {}
20+
}
21+
}
22+
const moreSubscriptions = await numbers.Subscription.listAsync(client, {});
23+
console.log(moreSubscriptions)
24+
// [
25+
// Subscription {
26+
// subscriptionId: '6be53e36-...-668ee3603d71',
27+
// orderType: 'portins',
28+
// emailSubscription: { email: '...@bandwidth.com', digestRequested: 'NONE' },
29+
// client: Client {
30+
// prepareRequest: [Function],
31+
// concatAccountPath: [Function],
32+
// prepareUrl: [Function],
33+
// xml2jsParserOptions: [Object]
34+
// },
35+
// id: '6be53e36-...-668ee3603d71'
36+
// }
37+
// ]
38+
}
39+
catch (e) {
40+
console.log('Error');
41+
console.log(e);
42+
}
43+
}
44+
45+
findAndDeleteSubscriptionById('b57094d3-...-25085d224b48');

lib/subscription.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ Subscription.list = function(client, query, callback){
3636
if(err){
3737
return callback(err);
3838
}
39-
var items = res.subscriptions || [];
39+
var items = res.subscriptions.subscription || [];
4040
if(!Array.isArray(items)){
4141
items = [items];
4242
}
4343
var result = items.map(function(item){
44-
var i = item.subscription;
44+
var i = item;
4545
i.client = client;
4646
i.__proto__ = Subscription.prototype;
4747
i.id = i.subscriptionId;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@bandwidth/numbers",
3-
"version": "1.2.0",
3+
"version": "1.2.1",
44
"description": "NodeJs Client library for Bandwidth Numbers API",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)