Inventory API: Code Cookbook

Reconcile computed inventory quantities

Use Inventory API to reconcile the inventory count calculated by Square with the results of a physical count (or the inventory reported by a trusted system).

Before you start
Permalink Get a link to this section

Step 1: Construct the request
Permalink Get a link to this section

Create a BatchChangeInventoryRequest containing one or more InventoryPhysicalCount objects. Each request assigns an explicit count to the indicated state.

InventoryPhysicalCount physicalCount1 = new InventoryPhysicalCount()
    .catalogObjectId(variation1Id)
    .locationId(locationId1)
    .state(InventoryPhysicalCount.StateEnum.IN_STOCK)
    .quantity("5");

InventoryPhysicalCount physicalCount2 = new InventoryPhysicalCount()
    .catalogObjectId(variation2Id)
    .locationId(locationId1)
    .state(InventoryPhysicalCount.StatesEnum.IN_STOCK)
    .quantity("12");

InventoryChange physicalCountChange1 = new InventoryChange().physicalCount(physicalCount1);
InventoryChange physicalCountChange2 = new InventoryChange().physicalCount(physicalCount2);

BatchChangeInventoryRequest physicalCountRequest = new BatchChangeInventoryRequest()
    .idempotencyKey(UUID.randomUUID().toString())
    .addChangesItem(physicalCountChange1)
    .addChangesItem(physicalCountChange2);

Step 2: Send the request
Permalink Get a link to this section

Send the BatchChangeInventoryRequest to the server. See the BatchChangeInventoryResponse endpoint in the Connect Technical Reference for details on all the available response fields.

BatchChangeInventoryResponse physicalCountResponse =
    inventoryApi.batchChangeInventory(physicalCountRequest);