The Plivo Java SDK makes it simpler to integrate voice and SMS communications into your Java applications using the Plivo REST API. Using the SDK, you’ll be able to make voice calls, send SMS messages, and generate Plivo 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 Plivo SDK as a dependency.
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 Plivo SDK as a dependency.
To make API requests, you need to create a Plivo instance and provide it with authentication credentials, which you can find on the Overview page of the Plivo console.We recommend that you store your credentials in the PLIVO_AUTH_ID and the PLIVO_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:
Copy
Ask AI
class Example { public static void main(String [] args) { Plivo.init(); }}
Alternatively, you can provide them to the Plivo.init() constructor yourself:
Copy
Ask AI
class Example { public static void main(String [] args) { Plivo.init("<auth_id>", "<auth_token>"); }}
Replace the auth placeholders with your authentication credentials from the Plivo console.To use multiple clients, create a PlivoClient instance yourself and set it on a request:
Copy
Ask AI
class Example { public static void main(String [] args) { PlivoClient client = new PlivoClient("<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 Plivo console. Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234).
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:
Copy
Ask AI
class Example { public static void main(String [] args) { Plivo.init("<auth_id>","<auth_token>"); for (Message message : Message.lister()) { System.out.println(message.getMessageUuid()); } }}
Please note that this makes several requests to the Plivo API, and will pause for a short duration at every 20 resources.
class Example { public static void main(String [] args) { Plivo.init("<auth_id>","<auth_token>"); Message.creator("the_source_number", "+14157654321", "Hello, world!") .create(); }}
Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phone number placeholders with actual phone numbers in E.164 format (for example, +12025551234).
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