Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails twilio api release number

I use twilio gem and I do not know how to release the phone number. I try:

@client.account.incoming_phone_numbers.delete(:phone_number => phone_number)

but rails say:

undefined method `delete' for #<Twilio::REST::IncomingPhoneNumbers:0x7f35c99e93e0>

How to correct release number?

like image 883
Nar Avatar asked Apr 12 '13 09:04

Nar


People also ask

How can I remove active number from twilio?

Login to the Twilio Console and select a subaccount by clicking the "View Subaccount" button next to the subaccount listed on your Subaccount Page. Then navigate to the Numbers tab and click the phone number(s) you wish to delete.

What is an API phone number?

Phone verification APIs are, as their name suggests, used to verify phone numbers. Verification APIs and services review phone numbers and make sure they're valid (i.e., they exist) and still in use. They can also be used to standardize phone numbers and identify geographic information for compliance purposes.

What is twilio Ruby?

The twilio-ruby helper library lets you write Ruby code to make HTTP requests to the Twilio API. This library is open source, so if you find a feature missing or a bug, we encourage you to contribute back to the twilio-ruby project hosted on GitHub.


2 Answers

I found solution:

@client.account.incoming_phone_numbers.list({:phone_number => phone_number}).each do |n|
  num = @client.account.incoming_phone_numbers.get(n.sid)
  num.delete
end
like image 169
Nar Avatar answered Nov 10 '22 04:11

Nar


Using the 5.x gem version and the new Twilio API's you have two options:

If you know the Number SID

client = Twilio::REST::Client.new(TWILIO_SID, TWILIO_TOKEN)
number = client.api.account.incoming_phone_numbers(PHONE_SID).fetch
number.delete

If you only know the phone number

client = Twilio::REST::Client.new(TWILIO_SID, TWILIO_TOKEN)
client.incoming_phone_numbers.list(phone_number: PHONE_NUMBER).each do |number|
  number.delete
end

Hope this helps new readers using the latest gem versions.

like image 20
Paulo Fidalgo Avatar answered Nov 10 '22 05:11

Paulo Fidalgo