Releasing Numbers
Overview
At some point, you may need to release a large quantity of numbers in order to purchase new ones. This can be tedious to delete one by one, so this example shows one way that you can release numbers in bulk with ease.
Full code example: Release Numbers
- Python
- Ruby
from signalwire.rest import Client as signalwire_client
# TODO: Update with your own credentials
project_id = "XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
access_token = "PTxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
space_url = "YOURSPACENAME.signalwire.com"
client = signalwire_client(
project_id,
access_token,
signalwire_space_url = space_url)
print('Would you like to delete all numbers with a specific area code? If so, enter it now. If not, press Enter to skip.: ')
area_choice = input()
print('Would you like to delete all numbers that contain a specific string? If so, enter it now. If not, press Enter to skip.: ')
contain_phrase_choice = input()
phone_numbers = client.incoming_phone_numbers.list()
filtered_numbers_list = []
if area_choice != "" or contain_phrase_choice != "":
for numberData in phone_numbers:
if numberData.phone_number.find(area_choice) != -1 and numberData.phone_number.find(contain_phrase_choice) != -1:
filtered_numbers_list.append(numberData)
print("Total Numbers -- " + str(len(filtered_numbers_list)))
for numberData in filtered_numbers_list:
print("Deleting number -- " + numberData.phone_number)
# TODO: Uncomment the next line to activate deleting the numbers
# client.incoming_phone_numbers(numberData.sid).delete()
require 'signalwire/sdk'
@client = Signalwire::REST::Client.new 'PROJECT_ID', 'AUTH_TOKEN', signalwire_space_url: "example.signalwire.com"
substring = "DELETE"
incoming_phone_numbers = @client.incoming_phone_numbers.list
incoming_phone_numbers.each do |record|
puts record.friendly_name
if (record.friendly_name.match(/#{substring}/))
puts "deleting number with sid #{record.sid} "
# @client.incoming_phone_numbers(record.sid).delete
end
end
What are we going to do?
Using this code snippet we will search through all of the numbers on your account and return/release those with a specific area code or sequence in their name.