Make a call with Java SDK

You can quickly see how the Voice API works by calling yourself using the API and the Java SDK.

In this guide you will learn:

  1. How to set up your Java application.
  2. How to call your phone number.
Note:

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

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 Voice app credentials from your Sinch Customer Dashboard, uncomment the following fields and populate them with your values:
FieldDescription
APPLICATION_API_KEYThe unique ID of your application.
APPLICATION_API_SECRETThe secret for your application.
  1. Save the file.

Modify your application

Navigate to the /templates/client/src/main/java/voice/ 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.

The code provided in Snippet.java contains some placeholder values. You'll need to update the parameters detailed in the following subsections with your values.

phoneNumber

In this example you want to call a phone number. Change the value of the phoneNumber parameter to the phone number you verified in your dashboard in E.164 format.
Note:

When your account is in trial mode, you can only call your verified numbers. If you want to call any number, you need to upgrade your account!

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.

Make your first call

Now you can execute the code and make your text-to-speech call. Run the following command:

Copy
Copied
java -jar target/sinch-java-sdk-client-application-1.0-SNAPSHOT-jar-with-dependencies.jar
You should receive a phone call to the number you called with the message "Hello, this is a call from Sinch. Congratulations! You made your first call." Additionally you should see the response with the callId in the console.

Next steps

Now that you know how to make a call, learn how to handle an incoming call.

Additional resources

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