I need to buy twilio numbers through nodejs. I could not find any answer regarding that. Is it really possible to buy twilio number through node.js ?
I really appreciate any guidance.
Thanks
See Alan's response for Twilio's docs. In short:
TWILIO_ACCOUNT_SID=AC...
TWILIO_AUTH_TOKEN=4f...
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.availablePhoneNumbers('CA')
.local
.list({ areaCode: 604, limit: 20 })
.then(local => local.forEach(l => console.log(l.friendlyName)));
CA is the country code and 604 is the area code
You will get a list of available phone numbers based on the country code and area code you provided in the get_available_numbers.js
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
client.incomingPhoneNumbers
.create({ phoneNumber: '+16047574779' })
.then(incoming_phone_number => console.log(incoming_phone_number.sid));
Where +16047574779 is one of the phone numbers from the list you got after running "node get_available_number.js"
You will get a response with information about your provisioned phone number