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 of a single item variation (for example, to show the quantity available when an item variation is select on an eCommerce site), call the RetreiveInventoryCountRequest endpoint with Catalog object ID of the item variation. You can also use a location ID to filter the search against specific locations. See the RetrieveInventoryCount endpoint in the Connect Technical Reference for details about the specific response fields.

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) {