# Rent the first available number using the Java SDK Use this guide to setup your Java application for use with the Numbers API and rent the first available Sinch virtual number and assign it to your SMS service plan. Note: Before you can get started, you need the following already set up: - - [JDK 8 or later](https://www.oracle.com/java/technologies/downloads/) and a familiarity with how to create a new Java application. - [Apache Maven](https://maven.apache.org/install.html) and a familiarity with how to use the Maven CLI. Steps: 1. [Set up](#set-up-your-java-application) your Java application 2. [Rent the first available virtual number](#rent-the-first-available-virtual-number) for SMS, Voice or both. ## 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](https://github.com/sinch/sinch-sdk-java-quickstart) repository. 2. Navigate to the `sinch-sdk-java-quickstart/getting-started/numbers/rent-first-available-number/client/src/main/resources` folder. 3. Open the `config.properties` [file](https://github.com/sinch/sinch-sdk-java-quickstart/blob/main/getting-started/numbers/rent-first-available-number/client/src/main/resources/config.properties). Using the [access key credentials](https://dashboard.sinch.com/settings/access-keys) from your Sinch Build Dashboard, populate the following fields with your values: | Field | Description | | --- | --- | | SINCH_PROJECT_ID | The unique ID of your Project. | | SINCH_KEY_ID | The unique ID of your access key. | | SINCH_KEY_SECRET | The 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 `getting-started/numbers/rent-first-available-number/client/src/main/java/numbers` folder and open the `Snippet.java` [file](https://github.com/sinch/sinch-sdk-java-quickstart/blob/main/getting-started/numbers/rent-first-available-number/client/src/main/java/numbers/Snippet.java). Snippet.java // This code rents the first available number and configures it for use. package numbers; import com.sinch.sdk.domains.numbers.api.v1.NumbersService; import com.sinch.sdk.domains.numbers.models.v1.ActiveNumber; import com.sinch.sdk.domains.numbers.models.v1.Capability; import com.sinch.sdk.domains.numbers.models.v1.NumberType; import com.sinch.sdk.domains.numbers.models.v1.SmsConfiguration; import com.sinch.sdk.domains.numbers.models.v1.request.AvailableNumberRentAnyRequest; import java.util.Collections; import java.util.logging.Logger; public class Snippet { private static final Logger LOGGER = Logger.getLogger(Snippet.class.getName()); static void execute(NumbersService numbersService) { String servicePlanId = "YOUR_service_plan_id"; String regionCode = "YOUR_region_code"; Capability capability = Capability.SMS; NumberType numberType = NumberType.LOCAL; LOGGER.info( String.format( "Sending request to rent the first available number and configure it with the" + " pre-configured service plan id '%s' to use the SMS capability", servicePlanId)); ActiveNumber response = numbersService.rentAny( AvailableNumberRentAnyRequest.builder() .setCapabilities(Collections.singletonList(capability)) .setType(numberType) .setRegionCode(regionCode) .setSmsConfiguration( SmsConfiguration.builder().setServicePlanId(servicePlanId).build()) .build()); LOGGER.info(String.format("Rented number: %s", response)); } } 1. The code provided in **Snippet.java** includes default and placeholder parameters. Replace the following following values for these parameters with your own values: | Parameter | Your value | | --- | --- | | `YOUR_region_code` | The two letter abbreviation of the country for which you'd like a number. For example, the United States is `US`. Should be in [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-2) format. | | `YOUR_service_plan_id` | Your [SMS service plan ID](https://dashboard.sinch.com/sms/api/rest). This is required for SMS configuration. | If you want, you can change the values of these enums to their other options: | Parameter | Your value | | --- | --- | | `Capability.SMS` | The capability of the number you would like to rent. Available options are `SMS` and `VOICE`. | | `NumberType.LOCAL` | 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`. For more information, see the [JavaDocs](https://www.javadoc.io/doc/com.sinch.sdk/sinch-sdk-java/latest/com/sinch/sdk/domains/numbers/models/v1/NumberType.html). | 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/getting-started/numbers/rent-first-available-number/client` folder and run the following command: ```Shell mvn package ``` This command creates the `target` folder and application. ## Rent the first available virtual number Now you can run the code with the following command: ```Shell java -jar target/sinch-java-sdk-client-application-1.0-SNAPSHOT-jar-with-dependencies.jar ``` This code will rent the first available number that fits the search criteria you specified and assign (or provision) it to your SMS service plan ID. You'll see the response in the console. ## Next steps Send a message to yourself using the SMS API to verify that the configuration was successful. - [Send an SMS message](/docs/sms/getting-started). ## Additional resources - Explore the [API specification](/docs/numbers/api-reference/numbers) to test more endpoints. - Prefer a UI to search for a number? Follow the entire number searching and renting process [in the Sinch Build Dashboard](https://dashboard.sinch.com/numbers/buy-numbers).