Assign a number to your SIP trunk with Python

You can manage your Elastic SIP trunks with the API and assign a phone number to your SIP trunk.

In this guide you will learn:
  1. How to set up your Python application.
  2. How to assign a phone number

What you need to know before you start

Before you can get started, you need the following already set up:

Set up your Python application and install dependencies

We'll be using the requests module to make HTTP requests. Open a command prompt and use the following command to install the requests module:
Copy
Copied
pip install requests
Create a new file named assign-number.py and paste the provided "assign-number.py" code found on this page into the file.
This code makes a POST request to the EST API /trunks/{SIP_TRUNK_ID}/phoneNumbers endpoint which assigns the phone number you specified in the phone_number variable.

Fill in your parameters

Before you can run the code, you need to update some values so you can connect to your Sinch account. Update the following parameters with your own values:

ParameterYour value
project_idThe project ID to which your SIP trunk belongs. You can find this on your Sinch dashboard.
sip_trunk_idThe ID of the SIP trunk to which you want to assign the number.
keyThe access key found on your Sinch dashboard.
secretThe access secret found on your Sinch dashboard.
phone_numberThe phone number you want to add to your SIP trunk.

Save the file.

Assign your phone number

Now you can execute the code and assign your phone number. Run the following command:

Copy
Copied
python assign-number.py

In your console, you should see a success response showing that the phone number was added to the SIP trunk.

Additional resources

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.