Skip to main content

Telnyx Development Environment Setup

Java

You'll need to ensure that you have at least Java JDK 1.8 installed on your computer. If Java isn’t installed, follow the installation instructions for your operating system. You can check this by running the following:

java -version

Note: After pasting the above content, Kindly check and remove any new line added

Check out the source on GitHub , or see Package on Maven Central

Install

Install the Telnyx SDK using Maven or Gradle .

The latest version can be found on our releases page.

Maven

Add the snip to your pom.xml file.

<dependency>
<groupId>com.telnyx.sdk</groupId>
<artifactId>telnyx</artifactId>
<version>{version}</version>
</dependency>

Note: After pasting the above content, Kindly check and remove any new line added

Gradle

Run the command

compile "com.telnyx.sdk:telnyx:{version}"

Note: After pasting the above content, Kindly check and remove any new line added

Send message example

Getting started

Demo below instanciates the Telnyx client

import com.telnyx.sdk.ApiClient;
import com.telnyx.sdk.ApiException;
import com.telnyx.sdk.Configuration;
import com.telnyx.sdk.auth.*;
import com.telnyx.sdk.model.*;
import com.telnyx.sdk.api.MessagesApi;

public class Example {

private static final String YOUR_TELNYX_NUMBER = "+19842550944";
private static final String YOUR_MOBILE_NUMBER = "+19198675309";
private static final String YOUR_TELNYX_API_KEY = "YOU_API_KEY";

public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
defaultClient.setBasePath("https://api.telnyx.com/v2");

// Configure HTTP bearer authorization: bearerAuth
HttpBearerAuth bearerAuth = (HttpBearerAuth) defaultClient.getAuthentication("bearerAuth");
bearerAuth.setBearerToken(YOUR_TELNYX_API_KEY);

MessagesApi apiInstance = new MessagesApi(defaultClient);
// CreateMessageRequest | Message payload
CreateMessageRequest createMessageRequest = new CreateMessageRequest()
.from(YOUR_TELNYX_NUMBER)
.to(YOUR_MOBILE_NUMBER)
.text("Hello From Telnyx");
try {
MessageResponse result = apiInstance.createMessage(createMessageRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling MessagesApi#createMessage");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}

Note: After pasting the above content, Kindly check and remove any new line added

On this page