Quickstart: Create and Manage Gift Cards with Customer Integration

Applies to: Customers API | Gift Cards API

Learn how to integrate the Customers API with the Gift Cards API to create or find customers and manage their gift cards.

Link to section

Prerequisites

Before you begin, you need the following:

  • A Square account (sign up for a free developer account if you don't have one).
  • An access token for the Square API. For more information, see Get Started.

The following language-specific requirements are needed to run the code samples:

  • Java 8 or later
  • Square Java SDK 35.0.0 or later
  • Gradle or Maven

Add this dependency to your build.gradle file:

implementation 'com.squareup:square:35.0.0'

Or to your pom.xml file:

<dependency> <groupId>com.squareup</groupId> <artifactId>square</artifactId> <version>35.0.0</version> </dependency>
Link to section

1. Initialize the Square client

Set up the Square client with your credentials.

import com.squareup.square.SquareClient; import com.squareup.square.Environment; public class GiftCardService { private final SquareClient client; public GiftCardService(String accessToken) { client = new SquareClient.Builder() .environment(Environment.SANDBOX) .accessToken(accessToken) .build(); } }
Link to section

2. Search for an existing customer

Search for a customer using their email address.

Link to section

3. Manage gift cards

Create a new gift card or retrieve existing ones for the customer.

Link to section

Complete example

The following is a complete example showing how to use the service:

Link to section

Next steps