The VTS Java SDK makes it simpler to integrate voice and SMS communications into your Java applications using the VTS REST API. Using the SDK, you’ll be able to make voice calls, send SMS messages, and generate VTS XML documents to control your call flows.
Supported Java versions: This SDK works with Java 1.8 and 1.9, meaning JDK 8 and JDK 9. While using the SDK with Java 1.9, you may have to use the --add-modules java.se.ee flag to include modules that are no longer present by default.
You can use this SDK by adding it as a dependency in your dependency management tool. Alternatively, you can use the JAR file.
If you’re using Maven, use this XML code to include the VTS SDK as a dependency.
<dependency>
<groupId>net.vtscom</groupId>
<artifactId>vts-java</artifactId>
<version>5.9.3</version>
</dependency>
If you’re using Gradle, use this line in your dependencies.
compile 'net.vtscom:vts-java:5.9.3'
You can see the full list of Java SDK releases on GitHub. You can use a beta SDK by adding it as a dependency in your dependency management tool. Alternatively, you can use the JAR file.
If you’re using Maven, use this XML code to include the VTS SDK as a dependency.
<dependency>
<groupId>net.vtscom</groupId>
<artifactId>vts-java</artifactId>
<version>4.3.0-beta-2</version>
</dependency>
If you’re using Gradle, use this line in your dependencies.
compile 'net.vtscom:vts-java:4.3.0-beta-2'
To make API requests, you need to create a VTS instance and provide it with authentication credentials, which you can find on the Overview page of the VTS console.
We recommend that you store your credentials in the VTS_AUTH_ID and the VTS_AUTH_TOKEN environment variables, to avoid the possibility of accidentally committing them to source control. If you do this, you can initialize the client with no arguments and it will automatically fetch them from the environment variables:
class Example {
public static void main(String [] args) {
vts.init();
}
}
Alternatively, you can provide them to the vts.init() constructor yourself:
class Example {
public static void main(String [] args) {
vts.init("<auth_id>", "<auth_token>");
}
}
Replace the auth placeholders with your authentication credentials from the VTS console.
To use multiple clients, create a VTSClient instance yourself and set it on a request:
class Example {
public static void main(String [] args) {
VTSClient client = new VTSClient("<auth_id>", "<auth_token>");
Message.creator("<caller_id>", "<destination_number>", "Hello, world!")
.client(client)
.create();
}
}
Replace the auth placeholders with your authentication credentials from the VTS console. Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234).
The SDK uses consistent interfaces to create, retrieve, update, delete, and list resources. The pattern is:
Resource.creator(parameters).create();
Resource.getter(parameters).get();
Resource.updater(identifier, parameters).update();
Resource.deleter(identifier).delete();
Resource.lister().list();
Using Resource.lister().list() lists the first 20 resources by default (the first page, with limit as 20, and offset as 0). Use limit and offset to get more pages of resources.
To list all objects of any resource, use the request object itself as an iterable:
class Example {
public static void main(String [] args) {
vts.init("<auth_id>","<auth_token>");
for (Message message : Message.lister()) {
System.out.println(message.getMessageUuid());
}
}
}
Please note that this makes several requests to the VTS API, and will pause for a short duration at every 20 resources.
class Example {
public static void main(String [] args) {
vts.init("<auth_id>","<auth_token>");
Message.creator("the_source_number", "+14157654321", "Hello, world!")
.create();
}
}
Replace the auth placeholders with your authentication credentials from the VTS console. Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234).
class Example {
public static void main(String [] args) {
vts.init("<auth_id>","<auth_token>");
Call.creator("<caller_id>", Collections.singletonList("<destination_number>"), "https://<answer.url>")
.answerMethod("GET")
.create();
}
}
class Example {
public static void main(String [] args) {
System.out.println(new Response()
.children(
new Speak("Hello, world!")
).toXmlString());
}
}
This generates the XML code:
<Response>
<Speak>Hello, world!</Speak>
</Response>
We’ve introduced a customizable logging mechanism in the Java SDK that enables you to choose the level of logging in your development/production environment.
| Log-level | Description |
| NONE | No logs |
| BASIC | Logs request and response line |
| HEADER | Logs request and response line along with their headers |
| BODY | Logs request and response line along with their headers and bodies |
package net.vtscom.api.samples.call;
import net.vtscom.api.VTS;
import net.vtscom.api.models.base.LogLevel;
class Example {
public static void main(String [] args) {
vts.init("<auth_id>","<auth_token>", LogLevel.NONE); // LogLevel.NONE is the default value.
// VTS.init("<auth_id>","<auth_token>", LogLevel.BASIC);
// VTS.init("<auth_id>","<auth_token>", LogLevel.BODY);
// VTS.init("<auth_id>","<auth_token>", LogLevel.HEADERS);
}
}
Refer to the VTS API Reference documentation for more examples.
Report feedback or problems with this SDK by opening an issue on GitHub.