Reputation: 69
i'v taken the following code straight from the twilio api explorer
// Twilio Credentials
var accountSid = 'A***************************b25';
var authToken = 'f5a***************************e2';
//require the Twilio module and create a REST client
var client = require('twilio')(accountSid, authToken);
client.availablePhoneNumbers('US').local.get({
excludeAllAddressRequired: "false",
excludeLocalAddressRequired: "false",
excludeForeignAddressRequired: "false"
}, function(err, data) {
data.incomingPhoneNumbers.forEach(function(number) {
console.log(number.PhoneNumber);
});
});
but i get the following TypeError resulting in a 500 response from sails.js
client.availablePhoneNumbers(...).local.get is not a function.
i went into the http://twilio.github.io/twilio-node/index.html to view the library directly and found the following works but returns a 404
client.availablePhoneNumbers.get(country).local.list(function(err,data){console.log(err,data)})
[Error: [404] Unable to fetch record.
{"code": 20404, "message": "The requested resource /2010-04-01/Accounts/US/AvailablePhoneNumbers/A***************************b25/Local.json was not found", "more_info": "https://www.twilio.com/docs/errors/20404", "status": 404}]
any help with this would be greatly appreciated.
Upvotes: 0
Views: 557
Reputation: 73027
Twilio developer evangelist here.
I can only apologise, through our investigation of your reports we've found a number of issues in our documentation relating to this API call. Could you drop me an email at [email protected], we'd love to send you something for drawing this to our attention.
Anyway, with the issues you found. The API explorer code was incorrect as it calls data.incomingPhoneNumbers
in the callback, where that should be data.availablePhoneNumbers
. You also need to call number.phoneNumber
with a lower case "p" in the callback. Try this code instead:
// Twilio Credentials
var accountSid = 'A***************************b25';
var authToken = 'f5a***************************e2';
//require the Twilio module and create a REST client
var client = require('twilio')(accountSid, authToken);
client.availablePhoneNumbers('US').local.get({
excludeAllAddressRequired: "false",
excludeLocalAddressRequired: "false",
excludeForeignAddressRequired: "false"
}, function(err, data) {
if (!err) {
data.availablePhoneNumbers.forEach(function(number) {
console.log(number.phoneNumber);
});
} else {
console.log("Error: ", err);
}
});
I will report the errors in the API explorer code and documentation so hopefully no one else is bitten by this issue.
Let me know if this helps.
Edit
This seems to be a disconnect between the 3.0.0-rc1 release of the Twilio module that is not backwards compatible with the old 2.x series.
I recommend you downgrade to [email protected] and use the code from above.
Upvotes: 1