Remove a number from your SIP trunk with Java

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

In this guide you will learn:
  1. How to set up your Java 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 all Elastic SIP Trunking API configuration settings.
  • JDK 8 or later and a familiarity with how to create a new Java application.
  • Gradle and a familiarity with how use the Gradle build tools.
  • A created SIP trunk.

Set up your Java application

Create a new folder where you want to keep your app project. Then, open a terminal or command prompt to that location.

Create a new Java application using Gradle with the following command:

Copy
Copied
gradle init
In the prompts, select that you want to create an application, name your project and source package app, and then accept the defaults for the rest of the options.

Modify your application

Open the App.java file in your project folder, located in \app\scr\main\java\app, and populate that file with the "App.java" code found on this page.
This code makes a POST request to the EST API /trunks/{SIP_TRUNK_ID}/phoneNumbers endpoint which removes the phone number you specified in the phoneNumber 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
projectIdThe project ID to which your SIP trunk belongs. You can find this on your Sinch dashboard.
sipTrunkIdThe 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.
phoneNumberThe phone number you want to remove from your SIP trunk.

Save the file.

Remove your phone number

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

Copy
Copied
gradle run

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

Additional resources

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