简体   繁体   中英

Twilio paging in phone number API - nodejs

I'm using the Twilio client, as mentioned in the documentation in node. I want to use pagination and also get total number of records(phone numbers) for a particular endpoint. I could not find any documentation related to it. This is the code I have used.

const client = require('twilio')(accountSid, authToken);

// Find and then purchase a phone number
client
  .availablePhoneNumbers('US')
  .local.list({
    areaCode: '510',
  })
  .then(data => {
    const number = data[0];
    return client.incomingPhoneNumbers.create({
      phoneNumber: number.phoneNumber,
    });
  })
  .then(purchasedNumber => console.log(purchasedNumber.sid));

Edit: I found out there is a way to pass pageNumber, pageSize. list({ pageNumber: 1 , pageSize: 10}) but the results retrieved are not the same. If I execute the above, two times different sets of results are retrieved. There is a availablePhoneNumbers('US').local.page({ pageNumber: 1 , pageSize: 10}) as well that also gives some random results.

Twilio developer evangelist here.

The available phone numbers resource does not have pagination and returns a random result set each time you request it. You can narrow down your search by filtering on the list for things like country code or whether it contains certain number patterns, but you can't enumerate the entire library of Twilio numbers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM