Announcing Square’s New Java SDK

Announcing Square’s New Java SDK

Use the New Java SDK to Integrate with Square APIs

We’re very pleased to announce our new Java SDK. You can use the SDK to integrate Square payments into your app. Run your business with Square APIs including Catalog, Customers, Employees, Inventory, Labor, Locations, Orders, and more.

To install the package, just run

mvn dependency:get=com.squareup:square:RELEASE

from the command line or install the client dynamically by adding a dependency to the POM for your project:


Then after importing a few SDK packages, you’ll be ready to instantiate a client with your Square access token.

import com.squareup.square.SquareClient;
SquareClient square = new SquareClient.Builder()

With a client, we’re ready to use the Square API. For example, we can list locations.

square.getLocationsApi().listLocationsAsync().thenAccept(result -> {
   // Business logic
}).exceptionally(exception -> {
   // Exception handling
   return null;

One of the great features in the new SDK is that the response object contains new rich information about both the request and response. These details can be used for control flow and debugging.

If you were previously using the square_connect Java package, you might be wondering how the new Java SDK compares. Let’s take a look! For example, let’s create the following customer along with their address:

Address bodyAddress = new Address.Builder()
   .addressLine1("500 Electric Ave")
   .addressLine2("Suite 600")
   .locality("New York")
CreateCustomerRequest body = new CreateCustomerRequest.Builder()
   .emailAddress("[email protected]")
   .note("a customer")

First, let’s look at how we used to create a customer with the deprecated square_connect SDK:

ApiClient defaultClient = Configuration.getDefaultApiClient();
CustomersApi customersApi = new CustomersApi();
try {
   CreateCustomerResponse result = customersApi.createCustomer(body);
} catch (ApiException e) {
   System.err.println("Exception when calling CustomersApi.createCustomer");

For comparison, let’s create the same customer with the new Square Java SDK:

SquareClient square = new SquareClient.Builder()
square.getCustomersApi().createCustomerAsync(body).thenAccept(result -> {
   System.out.println("Successfully created customer with id:"+ result.getCustomer().getId());
}).exceptionally(e -> {
   System.err.println("Exception when calling CustomersApi.createCustomer");
   return null;

That’s all there is to it! As you can see, the new Java SDK interface is much simpler, but provides richer data. The new package also ships with a ton of usability and debugging features.

Give the new Java SDK a try today by installing it with mvn dependency:get=com.squareup:square:RELEASE.

With the new Java SDK it’s easier than ever to use Square as a platform to run your business with Java. We can’t wait to see what you’ll build! If you have any questions or feedback, drop by our developer community. We’d love to hear from you.

View More Articles ›