Square Connect Java SDK Technical Reference

December 17, 2019 ยท View on GitHub

Square logo

Square Connect Java SDK Technical Reference


The Square Connect Java SDK is retired (EOL) as of 2019-12-17 and will no longer receive bug fixes or product updates.


Maven Central Apache-2 license

If you have feedback about the new SDKs, or just want to talk to other Square Developers, request an invite to the new slack community for Square Developers

Requirements

Java 8

Building the API client library requires Maven to be installed.

Installation

Option 1: Maven users

Add this dependency to your project's POM:

<dependency>
    <groupId>com.squareup</groupId>
    <artifactId>connect</artifactId>
    <version>2.20191120.0</version>
    <scope>compile</scope>
</dependency>

Option 2: Gradle users

Add this dependency to your project's build file:

compile "com.squareup:connect:2.20191120.0"

Option 3: Build and Install locally

To install the API client library to your local Maven repository, simply execute:

mvn install -DskipTests

To run tests, you would need to create below accounts.json under travis-ci folder.

{
  "US-Prod": {
    "email": "your_email",
    "access_token": "your_access_token",
    "location_id": "your_location_id",
    "application_id": "your_application_id"
  },
  "US-Prod-Sandbox": {
    "email": "your_email",
    "access_token": "your_sandbox_access_token",
    "location_id": "your_sandbox_location_id",
    "application_id": "your_sandbox_application_id"
  }
}
mvn install

Option 4: Others

At first generate the JAR by executing:

mvn package

Then manually install the following JARs:

  • target/connect-2.20191120.0.jar
  • target/lib/*.jar

Getting Started

Please follow the installation instruction and execute the following Java code:

import com.squareup.connect.ApiClient;
import com.squareup.connect.ApiException;
import com.squareup.connect.Configuration;
import com.squareup.connect.api.LocationsApi;
import com.squareup.connect.auth.OAuth;
import com.squareup.connect.models.Location;

import java.io.File;
import java.util.*;

public class Example {

    public static void main(String[] args) {
        ApiClient apiClient = Configuration.getDefaultApiClient();

        // Configure OAuth2 access token for authorization: oauth2
        OAuth oauth2 = (OAuth) apiClient.getAuthentication("oauth2");
        oauth2.setAccessToken("YOUR_ACCESS_TOKEN");

        // List all locations
        LocationsApi locationsApi = new LocationsApi();
        locationsApi.setApiClient(apiClient);

        try {
            List<Location> locations = locationsApi.listLocations().getLocations();
            System.out.println(locations);
        } catch (ApiException e) {
            System.err.println("Exception when calling API");
            e.printStackTrace();
        }
    }
}

How to configure sandbox environment


import com.squareup.connect.ApiClient;
import com.squareup.connect.ApiException;
import com.squareup.connect.Configuration;
import com.squareup.connect.api.LocationsApi;
import com.squareup.connect.auth.OAuth;
import com.squareup.connect.models.Location;

import java.io.File;
import java.util.*;

public class Example {

    public static void main(String[] args) {
        ApiClient apiClient = Configuration.getDefaultApiClient();
        // Set sandbox url
        apiClient.setBasePath('https://connect.squareupsandbox.com');

        // Configure OAuth2 access token for authorization: oauth2
        OAuth oauth2 = (OAuth) apiClient.getAuthentication("oauth2");
        // Set your sandbox token
        oauth2.setAccessToken("YOUR_SANDBOX_ACCESS_TOKEN");

        LocationsApi locationsApi = new LocationsApi();
    }
}

Documentation for API Endpoints

All URIs are relative to https://connect.squareup.com

ClassMethodHTTP requestDescription
ApplePayApiregisterDomainPOST /v2/apple-pay/domainsRegisterDomain
CatalogApibatchDeleteCatalogObjectsPOST /v2/catalog/batch-deleteBatchDeleteCatalogObjects
CatalogApibatchRetrieveCatalogObjectsPOST /v2/catalog/batch-retrieveBatchRetrieveCatalogObjects
CatalogApibatchUpsertCatalogObjectsPOST /v2/catalog/batch-upsertBatchUpsertCatalogObjects
CatalogApicatalogInfoGET /v2/catalog/infoCatalogInfo
CatalogApideleteCatalogObjectDELETE /v2/catalog/object/{object_id}DeleteCatalogObject
CatalogApilistCatalogGET /v2/catalog/listListCatalog
CatalogApiretrieveCatalogObjectGET /v2/catalog/object/{object_id}RetrieveCatalogObject
CatalogApisearchCatalogObjectsPOST /v2/catalog/searchSearchCatalogObjects
CatalogApiupdateItemModifierListsPOST /v2/catalog/update-item-modifier-listsUpdateItemModifierLists
CatalogApiupdateItemTaxesPOST /v2/catalog/update-item-taxesUpdateItemTaxes
CatalogApiupsertCatalogObjectPOST /v2/catalog/objectUpsertCatalogObject
CheckoutApicreateCheckoutPOST /v2/locations/{location_id}/checkoutsCreateCheckout
CustomersApicreateCustomerPOST /v2/customersCreateCustomer
CustomersApicreateCustomerCardPOST /v2/customers/{customer_id}/cardsCreateCustomerCard
CustomersApideleteCustomerDELETE /v2/customers/{customer_id}DeleteCustomer
CustomersApideleteCustomerCardDELETE /v2/customers/{customer_id}/cards/{card_id}DeleteCustomerCard
CustomersApilistCustomersGET /v2/customersListCustomers
CustomersApiretrieveCustomerGET /v2/customers/{customer_id}RetrieveCustomer
CustomersApisearchCustomersPOST /v2/customers/searchSearchCustomers
CustomersApiupdateCustomerPUT /v2/customers/{customer_id}UpdateCustomer
EmployeesApilistEmployeesGET /v2/employeesListEmployees
EmployeesApiretrieveEmployeeGET /v2/employees/{id}RetrieveEmployee
InventoryApibatchChangeInventoryPOST /v2/inventory/batch-changeBatchChangeInventory
InventoryApibatchRetrieveInventoryChangesPOST /v2/inventory/batch-retrieve-changesBatchRetrieveInventoryChanges
InventoryApibatchRetrieveInventoryCountsPOST /v2/inventory/batch-retrieve-countsBatchRetrieveInventoryCounts
InventoryApiretrieveInventoryAdjustmentGET /v2/inventory/adjustment/{adjustment_id}RetrieveInventoryAdjustment
InventoryApiretrieveInventoryChangesGET /v2/inventory/{catalog_object_id}/changesRetrieveInventoryChanges
InventoryApiretrieveInventoryCountGET /v2/inventory/{catalog_object_id}RetrieveInventoryCount
InventoryApiretrieveInventoryPhysicalCountGET /v2/inventory/physical-count/{physical_count_id}RetrieveInventoryPhysicalCount
LaborApicreateBreakTypePOST /v2/labor/break-typesCreateBreakType
LaborApicreateShiftPOST /v2/labor/shiftsCreateShift
LaborApideleteBreakTypeDELETE /v2/labor/break-types/{id}DeleteBreakType
LaborApideleteShiftDELETE /v2/labor/shifts/{id}DeleteShift
LaborApigetBreakTypeGET /v2/labor/break-types/{id}GetBreakType
LaborApigetEmployeeWageGET /v2/labor/employee-wages/{id}GetEmployeeWage
LaborApigetShiftGET /v2/labor/shifts/{id}GetShift
LaborApilistBreakTypesGET /v2/labor/break-typesListBreakTypes
LaborApilistEmployeeWagesGET /v2/labor/employee-wagesListEmployeeWages
LaborApilistWorkweekConfigsGET /v2/labor/workweek-configsListWorkweekConfigs
LaborApisearchShiftsPOST /v2/labor/shifts/searchSearchShifts
LaborApiupdateBreakTypePUT /v2/labor/break-types/{id}UpdateBreakType
LaborApiupdateShiftPUT /v2/labor/shifts/{id}UpdateShift
LaborApiupdateWorkweekConfigPUT /v2/labor/workweek-configs/{id}UpdateWorkweekConfig
LocationsApicreateLocationPOST /v2/locationsCreateLocation
LocationsApilistLocationsGET /v2/locationsListLocations
LocationsApiretrieveLocationGET /v2/locations/{location_id}RetrieveLocation
LocationsApiupdateLocationPUT /v2/locations/{location_id}UpdateLocation
MerchantsApilistMerchantsGET /v2/merchantsListMerchants
MerchantsApiretrieveMerchantGET /v2/merchants/{merchant_id}RetrieveMerchant
MobileAuthorizationApicreateMobileAuthorizationCodePOST /mobile/authorization-codeCreateMobileAuthorizationCode
OAuthApiobtainTokenPOST /oauth2/tokenObtainToken
OAuthApirenewTokenPOST /oauth2/clients/{client_id}/access-token/renewRenewToken
OAuthApirevokeTokenPOST /oauth2/revokeRevokeToken
OrdersApibatchRetrieveOrdersPOST /v2/locations/{location_id}/orders/batch-retrieveBatchRetrieveOrders
OrdersApicreateOrderPOST /v2/locations/{location_id}/ordersCreateOrder
OrdersApipayOrderPOST /v2/orders/{order_id}/payPayOrder
OrdersApisearchOrdersPOST /v2/orders/searchSearchOrders
OrdersApiupdateOrderPUT /v2/locations/{location_id}/orders/{order_id}UpdateOrder
PaymentsApicancelPaymentPOST /v2/payments/{payment_id}/cancelCancelPayment
PaymentsApicancelPaymentByIdempotencyKeyPOST /v2/payments/cancelCancelPaymentByIdempotencyKey
PaymentsApicompletePaymentPOST /v2/payments/{payment_id}/completeCompletePayment
PaymentsApicreatePaymentPOST /v2/paymentsCreatePayment
PaymentsApigetPaymentGET /v2/payments/{payment_id}GetPayment
PaymentsApilistPaymentsGET /v2/paymentsListPayments
RefundsApigetPaymentRefundGET /v2/refunds/{refund_id}GetPaymentRefund
RefundsApilistPaymentRefundsGET /v2/refundsListPaymentRefunds
RefundsApirefundPaymentPOST /v2/refundsRefundPayment
ReportingApilistAdditionalRecipientReceivableRefundsGET /v2/locations/{location_id}/additional-recipient-receivable-refundsListAdditionalRecipientReceivableRefunds
ReportingApilistAdditionalRecipientReceivablesGET /v2/locations/{location_id}/additional-recipient-receivablesListAdditionalRecipientReceivables
TransactionsApicaptureTransactionPOST /v2/locations/{location_id}/transactions/{transaction_id}/captureCaptureTransaction
TransactionsApichargePOST /v2/locations/{location_id}/transactionsCharge
TransactionsApicreateRefundPOST /v2/locations/{location_id}/transactions/{transaction_id}/refundCreateRefund
TransactionsApilistRefundsGET /v2/locations/{location_id}/refundsListRefunds
TransactionsApilistTransactionsGET /v2/locations/{location_id}/transactionsListTransactions
TransactionsApiretrieveTransactionGET /v2/locations/{location_id}/transactions/{transaction_id}RetrieveTransaction
TransactionsApivoidTransactionPOST /v2/locations/{location_id}/transactions/{transaction_id}/voidVoidTransaction
V1EmployeesApicreateEmployeePOST /v1/me/employeesCreateEmployee
V1EmployeesApicreateEmployeeRolePOST /v1/me/rolesCreateEmployeeRole
V1EmployeesApicreateTimecardPOST /v1/me/timecardsCreateTimecard
V1EmployeesApideleteTimecardDELETE /v1/me/timecards/{timecard_id}DeleteTimecard
V1EmployeesApilistCashDrawerShiftsGET /v1/{location_id}/cash-drawer-shiftsListCashDrawerShifts
V1EmployeesApilistEmployeeRolesGET /v1/me/rolesListEmployeeRoles
V1EmployeesApilistEmployeesGET /v1/me/employeesListEmployees
V1EmployeesApilistTimecardEventsGET /v1/me/timecards/{timecard_id}/eventsListTimecardEvents
V1EmployeesApilistTimecardsGET /v1/me/timecardsListTimecards
V1EmployeesApiretrieveCashDrawerShiftGET /v1/{location_id}/cash-drawer-shifts/{shift_id}RetrieveCashDrawerShift
V1EmployeesApiretrieveEmployeeGET /v1/me/employees/{employee_id}RetrieveEmployee
V1EmployeesApiretrieveEmployeeRoleGET /v1/me/roles/{role_id}RetrieveEmployeeRole
V1EmployeesApiretrieveTimecardGET /v1/me/timecards/{timecard_id}RetrieveTimecard
V1EmployeesApiupdateEmployeePUT /v1/me/employees/{employee_id}UpdateEmployee
V1EmployeesApiupdateEmployeeRolePUT /v1/me/roles/{role_id}UpdateEmployeeRole
V1EmployeesApiupdateTimecardPUT /v1/me/timecards/{timecard_id}UpdateTimecard
V1ItemsApiadjustInventoryPOST /v1/{location_id}/inventory/{variation_id}AdjustInventory
V1ItemsApiapplyFeePUT /v1/{location_id}/items/{item_id}/fees/{fee_id}ApplyFee
V1ItemsApiapplyModifierListPUT /v1/{location_id}/items/{item_id}/modifier-lists/{modifier_list_id}ApplyModifierList
V1ItemsApicreateCategoryPOST /v1/{location_id}/categoriesCreateCategory
V1ItemsApicreateDiscountPOST /v1/{location_id}/discountsCreateDiscount
V1ItemsApicreateFeePOST /v1/{location_id}/feesCreateFee
V1ItemsApicreateItemPOST /v1/{location_id}/itemsCreateItem
V1ItemsApicreateModifierListPOST /v1/{location_id}/modifier-listsCreateModifierList
V1ItemsApicreateModifierOptionPOST /v1/{location_id}/modifier-lists/{modifier_list_id}/modifier-optionsCreateModifierOption
V1ItemsApicreatePagePOST /v1/{location_id}/pagesCreatePage
V1ItemsApicreateVariationPOST /v1/{location_id}/items/{item_id}/variationsCreateVariation
V1ItemsApideleteCategoryDELETE /v1/{location_id}/categories/{category_id}DeleteCategory
V1ItemsApideleteDiscountDELETE /v1/{location_id}/discounts/{discount_id}DeleteDiscount
V1ItemsApideleteFeeDELETE /v1/{location_id}/fees/{fee_id}DeleteFee
V1ItemsApideleteItemDELETE /v1/{location_id}/items/{item_id}DeleteItem
V1ItemsApideleteModifierListDELETE /v1/{location_id}/modifier-lists/{modifier_list_id}DeleteModifierList
V1ItemsApideleteModifierOptionDELETE /v1/{location_id}/modifier-lists/{modifier_list_id}/modifier-options/{modifier_option_id}DeleteModifierOption
V1ItemsApideletePageDELETE /v1/{location_id}/pages/{page_id}DeletePage
V1ItemsApideletePageCellDELETE /v1/{location_id}/pages/{page_id}/cellsDeletePageCell
V1ItemsApideleteVariationDELETE /v1/{location_id}/items/{item_id}/variations/{variation_id}DeleteVariation
V1ItemsApilistCategoriesGET /v1/{location_id}/categoriesListCategories
V1ItemsApilistDiscountsGET /v1/{location_id}/discountsListDiscounts
V1ItemsApilistFeesGET /v1/{location_id}/feesListFees
V1ItemsApilistInventoryGET /v1/{location_id}/inventoryListInventory
V1ItemsApilistItemsGET /v1/{location_id}/itemsListItems
V1ItemsApilistModifierListsGET /v1/{location_id}/modifier-listsListModifierLists
V1ItemsApilistPagesGET /v1/{location_id}/pagesListPages
V1ItemsApiremoveFeeDELETE /v1/{location_id}/items/{item_id}/fees/{fee_id}RemoveFee
V1ItemsApiremoveModifierListDELETE /v1/{location_id}/items/{item_id}/modifier-lists/{modifier_list_id}RemoveModifierList
V1ItemsApiretrieveItemGET /v1/{location_id}/items/{item_id}RetrieveItem
V1ItemsApiretrieveModifierListGET /v1/{location_id}/modifier-lists/{modifier_list_id}RetrieveModifierList
V1ItemsApiupdateCategoryPUT /v1/{location_id}/categories/{category_id}UpdateCategory
V1ItemsApiupdateDiscountPUT /v1/{location_id}/discounts/{discount_id}UpdateDiscount
V1ItemsApiupdateFeePUT /v1/{location_id}/fees/{fee_id}UpdateFee
V1ItemsApiupdateItemPUT /v1/{location_id}/items/{item_id}UpdateItem
V1ItemsApiupdateModifierListPUT /v1/{location_id}/modifier-lists/{modifier_list_id}UpdateModifierList
V1ItemsApiupdateModifierOptionPUT /v1/{location_id}/modifier-lists/{modifier_list_id}/modifier-options/{modifier_option_id}UpdateModifierOption
V1ItemsApiupdatePagePUT /v1/{location_id}/pages/{page_id}UpdatePage
V1ItemsApiupdatePageCellPUT /v1/{location_id}/pages/{page_id}/cellsUpdatePageCell
V1ItemsApiupdateVariationPUT /v1/{location_id}/items/{item_id}/variations/{variation_id}UpdateVariation
V1LocationsApilistLocationsGET /v1/me/locationsListLocations
V1LocationsApiretrieveBusinessGET /v1/meRetrieveBusiness
V1TransactionsApicreateRefundPOST /v1/{location_id}/refundsCreateRefund
V1TransactionsApilistBankAccountsGET /v1/{location_id}/bank-accountsListBankAccounts
V1TransactionsApilistOrdersGET /v1/{location_id}/ordersListOrders
V1TransactionsApilistPaymentsGET /v1/{location_id}/paymentsListPayments
V1TransactionsApilistRefundsGET /v1/{location_id}/refundsListRefunds
V1TransactionsApilistSettlementsGET /v1/{location_id}/settlementsListSettlements
V1TransactionsApiretrieveBankAccountGET /v1/{location_id}/bank-accounts/{bank_account_id}RetrieveBankAccount
V1TransactionsApiretrieveOrderGET /v1/{location_id}/orders/{order_id}RetrieveOrder
V1TransactionsApiretrievePaymentGET /v1/{location_id}/payments/{payment_id}RetrievePayment
V1TransactionsApiretrieveSettlementGET /v1/{location_id}/settlements/{settlement_id}RetrieveSettlement
V1TransactionsApiupdateOrderPUT /v1/{location_id}/orders/{order_id}UpdateOrder

Documentation for Models

Documentation for Authorization

Authentication schemes defined for the API:

oauth2

  • Type: OAuth
  • Flow: accessCode
  • Authorization URL: https://connect.squareup.com/oauth2/authorize
  • Scopes:
    • BANK_ACCOUNTS_READ: HTTP Method: `GET` Grants read access to bank account information associated with the targeted Square account. For example, to call the Connect v1 ListBankAccounts endpoint.
    • CUSTOMERS_READ: HTTP Method: `GET` Grants read access to customer information. For example, to call the ListCustomers endpoint.
    • CUSTOMERS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to customer information. For example, to create and update customer profiles.
    • EMPLOYEES_READ: HTTP Method: `GET` Grants read access to employee profile information. For example, to call the Connect v1 Employees API.
    • EMPLOYEES_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to employee profile information. For example, to create and modify employee profiles.
    • INVENTORY_READ: HTTP Method: `GET` Grants read access to inventory information. For example, to call the RetrieveInventoryCount endpoint.
    • INVENTORY_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to inventory information. For example, to call the BatchChangeInventory endpoint.
    • ITEMS_READ: HTTP Method: `GET` Grants read access to business and location information. For example, to obtain a location ID for subsequent activity.
    • ITEMS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to product catalog information. For example, to modify or add to a product catalog.
    • MERCHANT_PROFILE_READ: HTTP Method: `GET` Grants read access to business and location information. For example, to obtain a location ID for subsequent activity.
    • ORDERS_READ: HTTP Method: `GET` Grants read access to order information. For example, to call the BatchRetrieveOrders endpoint.
    • ORDERS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to order information. For example, to call the CreateCheckout endpoint.
    • PAYMENTS_READ: HTTP Method: `GET` Grants read access to transaction and refund information. For example, to call the RetrieveTransaction endpoint.
    • PAYMENTS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to transaction and refunds information. For example, to process payments with the Payments or Checkout API.
    • PAYMENTS_WRITE_ADDITIONAL_RECIPIENTS: HTTP Method: `POST`, `PUT`, `DELETE` Allow third party applications to deduct a portion of each transaction amount. Required to use multiparty transaction functionality with the Payments API.
    • PAYMENTS_WRITE_IN_PERSON: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to payments and refunds information. For example, to process in-person payments.
    • SETTLEMENTS_READ: HTTP Method: `GET` Grants read access to settlement (deposit) information. For example, to call the Connect v1 ListSettlements endpoint.
    • TIMECARDS_READ: HTTP Method: `GET` Grants read access to employee timecard information. For example, to call the Connect v2 SearchShifts endpoint.
    • TIMECARDS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to employee shift information. For example, to create and modify employee shifts.
    • TIMECARDS_SETTINGS_READ: HTTP Method: `GET` Grants read access to employee timecard settings information. For example, to call the GetBreakType endpoint.
    • TIMECARDS_SETTINGS_WRITE: HTTP Method: `POST`, `PUT`, `DELETE` Grants write access to employee timecard settings information. For example, to call the UpdateBreakType endpoint.

oauth2ClientSecret

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header

Pagination of V1 Endpoints

V1 Endpoints return pagination information via HTTP headers. In order to obtain response headers and extract the batch_token parameter you will need to follow the following steps:

  1. Use the full information endpoint methods of each API to get the response HTTP Headers. They are named as their simple counterpart with a WithHttpInfo suffix. Hence listEmployeeRoles would be called listEmployeeRolesWithHttpInfo. This method returns a CompleteResponse object with the response data deserialized along with a helper to retrieve the token if present.

  2. Use String batchToken = completeResponse.getBatchToken(); to extract the token and proceed to get the following page if a token is present.

Example

// Import classes:
//import .ApiClient;
//import .ApiException;
//import .Configuration;
//import .CompleteResponse;
//import .auth.*;
//import .api.V1EmployeesApi;

ApiClient defaultClient = Configuration.getDefaultApiClient();

// Configure OAuth2 access token for authorization: oauth2
OAuth oauth2 = (OAuth) defaultClient.getAuthentication("oauth2");
oauth2.setAccessToken("YOUR ACCESS TOKEN");

V1EmployeesApi apiInstance = new V1EmployeesApi();
String order = "order_example"; // String | The order in which employees are listed in the response, based on their created_at field.Default value: ASC
Integer limit = 56; // Integer | The maximum integer number of employee entities to return in a single response. Default 100, maximum 200.
String batchToken = null;
try {
    do {
        CompleteResponse<List<V1EmployeeRole>> completeResponse = apiInstance.listEmployeeRoles(order, limit, batchToken);
        System.out.println(completeResponse.getData());

        batchToken = completeResponse.getBatchToken();
    } while (batchToken != null);
} catch (ApiException e) {
    System.err.println("Exception when calling V1EmployeesApi#listEmployeeRoles");
    e.printStackTrace();
}

Recommendation

It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issues.

Author

developers@squareup.com