Java SDK

The Java SDK(s) are available via Maven & Github

Links Description Github
com.bandwidth.sdk/bandwidth-sdk Manage Phone Calls with BXML, Create outbound calls, SMS messages, MMS messages
com.bandwidth.sdk/bandwidth-java-iris-sdk Manage phone numbers and account settings
Code Examples Java code examples

Release Notes

Version Notes
2.0.0 Removed all messaging exceptions and normalized them under MessagingException
3.0.0 Updated Pause and SendDtmf BXML attributes
3.1.0 Added MFA functions
3.2.0 Added support for multi nested verbs in Gathers
3.3.0 Added support for Conference BXMl and Conference API Endpoints
3.4.0 Updated MFA schema to include digits and expirationTimeInMinutes
3.5.0 Added BXML Bridge verb
3.6.0 Added get conference endpoint
3.7.0 Added WebRTC API
3.8.0 Added conference management endpoints
4.0.0 Renamed CallEngineModifyConferenceRequest to ApiModifyConferenceRequest, and removed from and digits from TwoFactorVerifyRequestSchema
5.0.0 Added get messages function, and updated the body parameter in the create message function to be required. Updated the MFA error bodies and added message priority
6.0.0 Updated voice, messaging, and MFA objects as well as corrected WebRTC participantId and sessionId parameter ordering in a number of requests.

Download & Install


<!-- -->

Initialize Bandwidth Client

//Set the voice client configuration with credentials
BandwidthClient client = new BandwidthClient.Builder()
            .messagingBasicAuthCredentials("MESSAGING_API_TOKEN", "MESSAGING_API_SECRET")
            .voiceBasicAuthCredentials("VOICE_API_USERNAME", "VOICE_API_PASSWORD")
            .multiFactorAuthBasicAuthCredentials("username", "password")
            .environment(com.bandwidth.Environment.CUSTOM) // Optional - sets the enviroment to a custom base URL
            .baseUrl("") // Optional - sets the base Url

//Fully qualified name to remove conflicts
com.bandwidth.messaging.controllers.APIController messagingController = client.getMessagingClient().getAPIController();
com.bandwidth.voice.controllers.APIController voiceController = client.getVoiceClient().getAPIController();

Create Phone Call

import com.bandwidth.voice.models.ApiCreateCallRequest;

//Create the CreateCallRequest object and populate.
CreateCallRequest callRequest = new CreateCallRequest();


//The voice client createCall can throw these exceptions.
try {
    ApiResponse<ApiCallResponse> response = voiceController.createCall("", callRequest);
} catch (IOException | ApiException e) {

Generate BXML

import com.bandwidth.sdk.voice.models.verbs.*;

//Create a Bandwidth XML (BXML) SpeakSentence Verb.  Supply the sentence to be spoken.
SpeakSentence speakSentence = SpeakSentence.builder()
    .text("Hello World")

//Create the response object and add the speakSentence verb to the response.
Response response = Response.builder().build().add(speakSentence);

//view the BXML
System.out.println( response.toXml() )

Send Text Message

import com.bandwidth.messaging.models.MessageRequest;

MessageRequest messageRequest = new MessageRequest();

List<String> toNumbers = new ArrayList<>();


messageRequest.setText("Hey, check this out!");
messageRequest.setTo( toNumbers );
messageRequest.setTag("test tag");

try {
    ApiResponse<BandwidthMessage> response = messagingController.createMessage(accountId, messageRequest);
} catch (ApiException  | IOException e){

Order Phone Number

//Coming soon

Error Handling

All SDK methods can raise 2 types of exceptions based on the API response received.

The first type of exceptions are expected endpoint responses. The exception throw varies on each method and the corresponding http status code.

The second type of exceptions are unexpected endpoint responses. The exception throw will always be a ApiException.

Error Handling Example: Messaging

<import statements>

<client initialization code>

ApiResponse<BandwidthMessage> response = null;
try {
    response = controller.createMessage(accountId, messageRequest);
} catch (MessagingException ex){
} catch (ApiException  ex){

results matching ""

    No results matching ""