Based on the API documentation on twilio.com, twilio.availablePhoneNumbers('COUNTRY_CODE').mobile.get()
should exist. I should be able to call something like this below:
twilio.availablePhoneNumbers('US').mobile.get({
smsEnabled: true
}).then(function(searchResults) {
....
});
But when I used twilio module provided inside Parse cloud code, twilio.availablePhoneNumbers('COUNTRY_CODE').local
and twilio.availablePhoneNumbers('COUNTRY_CODE').tollFree
are available.
Am I wrong?
I need to programmatically acquire a phone number in the cloud code. If twilio on Parse cloud code is limited, how can I use the latest twilio APIs?
Twilio developer evangelist here.
The Twilio module on Parse is indeed outdated. I am currently working with their team to get an updated version available for developers like yourself.
In the meantime, you could use a normal HTTP request on Parse without the Twilio module to make calls like the one you are after. Something like this might work for now:
var accountSid = 'AC123...'; // your account SID
var authToken = 'xyzabc...'; // your auth token
var countryCode = 'US'; // the country code you want to search within
var url = 'https://';
url += accountSid + ':' + authToken + '@'; // add auth to URL
url += 'api.twilio.com/2010-04-01/Accounts/';
url += accountSid;
url += '/AvailablePhoneNumbers/';
url += countryCode;
url += '/Mobile.json';
Parse.Cloud.httpRequest({
url: url,
}).then(function(httpResponse) {
// success
console.log(httpResponse.text);
// httpResponse.data is the parsed JSON response
},function(httpResponse) {
// error
console.error('Request failed with response code ' + httpResponse.status);
});
You might want to check out the documentation for Parse's Parse.Cloud.httpRequest
. It's available here: https://parse.com/docs/cloudcode/guide#cloud-code-advanced