Inventory API: Code Cookbook

Retrieve IN_STOCK Quantities for a Specific Item Variation

Before you start Permalink Get a link to this section

Request quantities for a single item variation Permalink Get a link to this section

To request the IN_STOCK quantity for a single item variation (for example, to show the quantity available when an item variation is selected on an eCommerce site), call the RetreiveInventoryCountRequest endpoint with the catalog object ID of the item variation. You can also use a location ID to filter the search against specific locations. For details about the specific response fields, see the RetrieveInventoryCount endpoint.

String cursor = null; // Fetch initial page of results
while (true) {
    RetrieveInventoryCountResponse countResponse =
        inventoryApi.retrieveInventoryCount(variation1Id, locationId1, cursor);
    for (InventoryCount count: countResponse.getCounts()) {
        System.out.println("item variation " + count.getCatalogObjectId() +
            " at location " + count.getLocationId() + ":");
        System.out.println("  state: " + count.getState());
        System.out.println("  quantity: " + count.getQuantity());
        System.out.println("  calculated at: " + count.getCalculatedAt());
    }

    // Use cursor from response to fetch additional pages.
    cursor = countResponse.getCursor();
    if (cursor == null || cursor.length() == 0) {
        break;
    }
}