Order groceries end-to-end

Full Instamart journey - find products, build a cart, checkout, track delivery.

Instamart is Swiggy's quick-commerce grocery service across 1000+ Indian cities. Same shape as Food (discover → cart → order → track), different catalogue.

The flow

get_addresses
     │
     ▼
search_products ──► update_cart ──► get_cart ──► checkout ──► get_delivery_status
     ▲                  │
     └──────────────────┘
     your_go_to_items (bypass search)

Step 1 - Resolve the delivery address

// readToolData: see /docs/build/read-tool-results - returns structuredContent, throws on failure
const { addresses, resolution } = readToolData(
  await client.callTool({ name: "get_addresses", arguments: {} }),
);
const home =
  addresses.find((a) => a.id === resolution.defaultAddressId) ??
  addresses.find((a) => a.addressCategory === "Home") ??
  addresses[0];

If the user has no addresses, walk them through create_address.

Step 2 - Find products (or reorder)

Two paths. For quick reorders:

const goTo = readToolData(
  await client.callTool({
    name: "your_go_to_items",
    arguments: { addressId: home.id },
  }),
);
// goTo.products has frequently-ordered products - present as one-tap add

For search:

const results = readToolData(
  await client.callTool({
    name: "search_products",
    arguments: { addressId: home.id, query: "bananas" },
  }),
);

Each product returns one or more variations with their own spinId (the SKU-level identifier). You add variations to the cart, not the parent product.

The response may also include a similarProducts array — related items shown when the catalogue API finds relevant alternatives. Present these in a separate "Similar Items" section below the main results.

Step 3 - Build the cart

const variation = results.products
  .flatMap((p) => p.variations)
  .find((v) => v.isInStockAndAvailable);
 
// update_cart replaces the cart with this list - send every item the user wants
readToolData(
  await client.callTool({
    name: "update_cart",
    arguments: {
      selectedAddressId: home.id,
      items: [{ spinId: variation.spinId, skuId: variation.skuId, quantity: 2 }],
    },
  }),
);

Swapping address mid-cart? Don't. Run clear_cart first to avoid cross-address SKU mismatches.

Step 4 - Review the cart

const cart = readToolData(await client.callTool({ name: "get_cart", arguments: {} }));
// cart.items, cart.billBreakdown.toPay.value, cart.availablePaymentMethods

Check cart.addressWarning, cart.cartWarning, and cart.unserviceableItems before checkout; Instamart has a ₹99 minimum and service-area restrictions.

Step 5 - Checkout

const order = readToolData(
  await client.callTool({
    name: "checkout",
    arguments: { addressId: home.id, paymentMethod: "COD" },
  }),
);

This uses COD. To take payment with UPI, call get_payment_options first and pass the picked method into checkout (paymentMethod:"UPI" + intentApp/generateUPIQR) - see the Pay with UPI recipe.

Same non-idempotency rule as Food: if checkout 5xxs, check get_orders before retrying.

Step 6 - Track

const status = readToolData(
  await client.callTool({
    name: "get_delivery_status",
    arguments: { orderId: order.orderId, addressId: home.id },
  }),
);
// status.etaText, status.delivered; ETA typically 10-20 min post-checkout

Poll no faster than status.pollIntervalSec, and stop when cancelled or delivered is true. Live ETA isn't enabled for every account: if status.disabled is true, no ETA will follow, so stop polling and use track_order instead. track_order also gives a richer view (rider location, items), but it needs the delivery address's lat/lng, which get_addresses doesn't return.

Agent prompt

Common errors

Until the symbolic error.code registry ships (see errors), classify by error.message text. Expect:

  • Item out of stock at this address → suggest alternatives from search_products.
  • Address not serviceable → Instamart doesn't deliver here; ask for another address or offer Food.
  • Minimum order not met (cart under ₹99) → prompt user to add items.
  • Cart expired / abandoned → rebuild the cart.