How to Make a Phone Call in Java Using Plivo’s Voice API

Your company has settled on Plivo to handle its voice and messaging communications, and now it’s your job to start integrating Plivo into your company’s applications. Don’t worry — Plivo has an SDK to help you out. Let’s see how to make outbound calls and receive incoming calls through Plivo in a Java application.

Install the Plivo SDK


If you don’t want to use IntelliJ IDEA, you can download the jar file from our GitHub repo.

Find your Auth ID and Auth Token

Choose a phone number

Use PHLO to set up an outbound call

Let’s start with a very simple workflow. From the list of components on the left side, drag and drop the Initiate Call component onto the canvas, then connect the Start node to the Initiate Call node using the API Request trigger state.

Now you can add configuration information for the call in the right pane. Valid phone numbers begin with a plus sign and a country code. Add a caller ID number in the From field and a destination number in the To field, then click Validate to save the configuration.

PHLO lets you use variables for From and To values, but we’re keeping it simple for this example.

Now drag the Play Audio component onto the canvas. Connect the Initiate Call node to Play Audio using the Answered trigger state. In the Configuration panel, enter the text you want to play for the call recipient, then click Validate.

That’s all we’re going to do for now — we told you it was simple. Give the PHLO a name by clicking on the pencil icon in the upper left, then click the Save button in the upper right.

Run the PHLO to make a call

package com.example.demo;
import com.plivo.api.Plivo;
import com.plivo.api.PlivoClient;
import com.plivo.api.exceptions.PlivoRestException;
import com.plivo.api.models.phlo.Phlo;
import com.plivo.api.models.phlo.PhloUpdateResponse;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
public class PlivoVoiceApplication {
public static void main(String[] args) {, args);
public PhloUpdateResponse triggerPhlo() throws IOException, PlivoRestException {
final String authId = "auth_id";
final String authToken = "auth_token";
PlivoClient client = new PlivoClient(authId, authToken);
String phloId = "PHLO_ID";
Plivo.init(authId, authToken);
Phlo phlo = Phlo.getter(phloId).client(client).get();
PhloUpdateResponse response = Phlo.updater(phloId).run();
return response;

Substitute actual values for auth_id, auth_token, and PHLO_ID. Save the file and run it from Intellij.

Boom — you’ve made an outbound call.

Note: To set up your Java dev environment using Spring framework in less than 5 minutes, refer to the Java quickstart using Spring framework guide.

Set up inbound calls

Before you can receive a call using this PHLO, you have to assign it to a Plivo number. Go back to the Plivo console and click on Phone Numbers on the left navbar. From the list of Your Numbers, click on the number you want to use. On the next screen, from the Application Type dropdown, choose PHLO. From the PHLO Name dropdown, choose the PHLO you just created. Then click Update Number at the bottom of the screen.

Guess what? You’re done! You don’t have to run a program for this PHLO to work. Just call the Plivo number you specified and you should hear the message you configured read by Plivo’s text-to-speech processor.


Haven’t tried Plivo yet? Getting started is easy and only takes 5 minutes! Sign up today.

Originally published at on Feb12, 2021.

Developer Evangelist