Rent and configure your virtual number using Java

After searching for a number, rent and configure that number for SMS.

Note:

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

Steps:
  1. Set up your Java application
  2. Rent and configure the virtual number for SMS.

Set up your Java application

To quickly get started setting up a simple client application using the Java SDK:

  1. If you haven't already, clone the sinch-sdk-java-quickstart repository.
  2. Navigate to the templates/client/src/main/resources folder.
  3. Open the config.properties file. Using the access key credentials from your Sinch Customer Dashboard, populate the following fields with your values:
FieldDescription
SINCH_PROJECT_IDThe unique ID of your Project.
SINCH_KEY_IDThe unique ID of your access key.
SINCH_KEY_SECRETThe secret that goes with your access key.
Note: For security reasons, this secret is only visible right after access key creation.
  1. Save the file.

Modify your application

  1. Navigate to the /templates/client/src/main/java/numbers/ folder and open the Snippet.java file. Replace the existing content within that file with the Snippet.java code provided on this page. That code is also found here if you want to just replace the file.
  1. The code provided in Snippet.java includes placeholder parameters. Replace the following values for these parameters with your own values:
ParameterYour value
YOUR_service_plan_idYour SMS service plan IDThis is only required for SMS configuration.
YOUR_phone_numberThe virtual phone number that you previously searched for and would like to rent.
  1. Save the file.

Package the application

Now that you've modified the application, you need to use the Maven CLI to create a package that you can then execute. Open a command prompt or terminal to the sinch-sdk-java-quickstart/templates/client folder and run the following command:
Copy
Copied
mvn package
This command creates the target folder and application.

Rent and configure the virtual number

Now you can run the code with the following command:

Copy
Copied
java -jar target/sinch-java-sdk-client-application-1.0-SNAPSHOT-jar-with-dependencies.jar

Response

You should get a response similar to this one:

Copy
Copied
{
  "phoneNumber": "+12025550134",
  "projectId": "51bc3f40-f266-4ca8-8938-a1ed0ff32b9a",
  "displayName": "string",
  "regionCode": "US",
  "type": "MOBILE",
  "capability": [
    "SMS"
  ],
  "money": {
    "currencyCode": "USD",
    "amount": "2.00"
  },
  "paymentIntervalMonths": 0,
  "nextChargeDate": "2019-08-24T14:15:22Z",
  "expireAt": "2019-08-24T14:15:22Z",
  "smsConfiguration": {
    "servicePlanId": "82b42acf74924bd687ef9fb212f2060c",
    "scheduledProvisioning": {
      "servicePlanId": "82b42acf74924bd687ef9fb212f20611",
      "status": "WAITING",
      "lastUpdatedTime": "2019-08-24T14:15:22Z",
      "campaignId": "string",
      "errorCodes": [
        "INTERNAL_ERROR"
      ]
    },
    "campaignId": "string"
  },
  "voiceConfiguration": {
    "appId": "string",
    "scheduledVoiceProvisioning": {
      "appId": "string",
      "status": "WAITING",
      "lastUpdatedTime": "2019-08-24T14:15:22Z"
    },
    "lastUpdatedTime": "2019-08-24T14:15:22Z"
  }
}

Next steps

Send a message to yourself using the SMS API to verify that the configuration was successful.

Additional resources

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