Search for a virtual number using Python
Use this guide to setup your Python application for use with the Numbers API to search for an available Sinch virtual number.
Note:
Before you can get started, you need the following already set up:
- All Numbers API prerequisite steps.
- Python and a familiarity with how to create a new file.
Prefer an SDK? Find the Numbers SDK getting started guide here.
Steps:
- Set up your Python application
- Search for an available virtual number for SMS, Voice or both.
Set up your Python application
- Create a new file named
search-number.py
and paste the provided code found on this page into the file.
- Once you activate your virtual environment, install
requests
if it wasn't previously installed.
pip install requests
This guide covers HTTP
Search for an available virtual number
- Assign your values to the following required parameters:
Parameter | Your value |
---|---|
YOUR_ProjectID | The project_id can be found in the Customer Dashboard. |
YOUR_username | The username is your client_id or key_id and is found in the Sinch Customer Dashboard. |
YOUR_password | Your client_secret or key_secret . This is generated upon new key creation. Generate a new key if you have lost your secret key. |
regionCode | The two letter abbreviation of the country for which you'd like a number. ISO 3166–1 alpha–2. |
type | The type of number you would like to rent. Available options are: MOBILE , LOCAL , or TOLL_FREE . Note that 10DLC numbers should be set to LOCAL . |
Want to set additional search criteria?
Check out the the API reference, then the corresponding endpoint, for a list of additional search parameters.
- Save the file.
- Execute the code to search for an available number. Open a command prompt or terminal to the location where your Python file is saved and run the following command:
python search-number.py
Response
These steps should return a JSON list of numbers available to rent.
{
"availableNumbers": [
{
"phoneNumber": "+12089087284",
"regionCode": "US",
"type": "LOCAL",
"capability": ["SMS"],
"setupPrice": {
"currencyCode": "USD",
"amount": "0.00"
},
"monthlyPrice": {
"currencyCode": "USD",
"amount": "2.00"
},
"paymentIntervalMonths": 1
}
]
}
Next steps
Copy thephoneNumber
you would like to use and rent your virtual number using the Numbers API.Additional resources
- Explore the API specification to test more endpoints.
- Prefer a UI to search for a number? Follow the entire number searching and renting process in the Customer Dashboard.