List Numbers to CSV

List all of the numbers in your SignalWire Project and export them to CSV

To quickly run this code, check out our recipe below and replace the variables with your own!

Or, read our step-by-step walkthrough to learn more about this snippet!

Why do you need it?

This snippet might be helpful to you if you need to separately store a list of all your SignalWire numbers within a project. You can use one or more of the following parameters to further filter your records and return only the specific information that you need: FriendlyName, Origin, PhoneNumber.

What does it do?

This code will query your project and return all of the numbers in your project, limited by whatever parameters you choose to use. It will then take this data and insert it into a CSV for your records or further use.

System/Technical specifications

You MUST have pandas installed and imported for this to work. pandas is required to create the dataframe and export it to CSV.

You must have the SignalWire Python SDK installed. You can install that here.

Change the following variables

ProjectID - Your project ID is an alphanumeric string that tells the SignalWire SDK where to find your project. You can find this in an easily copyable format by going to your SignalWire Portal and clicking the API tab on the left-hand side.

AuthToken - Your Auth Token is an alphanumeric string that helps to authenticate your HTTP requests to SignalWire. You can create this (if you haven’t already) or copy this in an easily copyable format by going to your SignalWire Portal and clicking the API tab. If you have not created an API token, press the blue new button. If you have, click show and copy the string.

SpaceURL - Your space URL is the domain of your space, i.e. example.signalwire.com. This can also be found in an easily copyable format within the API tab in your SignalWire space.

If you want to add a parameter that you can filter the numbers by, you can add it within client.incoming_phone_numbers_list().

The snippet

from signalwire.rest import Client as signalwire_client
import pandas as pd

client = signalwire_client("ProjectID", "AuthToken", signalwire_space_url = 'SpaceUrl')

# Lists all numbers on account
incoming_phone_numbers = client.incoming_phone_numbers.list()

# Sets up an empty array
d = []

# Appends incoming phone numbers into
for record in incoming_phone_numbers:
   d.append((record.phone_number, record.sid))

print(d)

# Puts message log array into dataframe with headers for easier reading.
df = pd.DataFrame(d, columns=('Phone Number', 'PhoneNumberSID'))

print('dataframe')
print('\n')
print(df)

# Exports dataframe to csv, index=False turns off the indexing for each row
df.to_csv('Numbers.csv', index=False, encoding='utf-8')

Getting started guide

If you are looking for more information about using SignalWire, refer to our Getting Started guide.

Please feel free to reach out to us on our Community Slack or create a Support ticket if you need guidance!

Start a free trial

If you would like to test this example out, you can create a SignalWire account and space here.


Did this page help you?