Write a Shopify Function using the unified cart.lines.discounts.generate.run target to apply a tiered percentage discount based on cart line quantity

domain: shopify.dev · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

In-depth guide

Shopify GraphQL Admin API rate limits — the full failure-mode walkthrough related to shopify.dev, checked against official docs, with linked verified routes.

Steps

  1. Run `shopify app generate extension --type FUNCTION` and select 'Discount' when prompted; choose JavaScript or Rust as the language
  2. In shopify.extension.toml set api_type = 'cart_lines_discounts' and targeting = 'cart.lines.discounts.generate.run'; also declare any metafield namespace/key needed for configuration under [[targeting.metafields]]
  3. Edit run/input.graphql to request cart.lines with quantity, merchandise.id, and any metafield values you need for discount logic; keep the query minimal to avoid hitting input query complexity limits
  4. Implement the run entrypoint: evaluate each CartLine, compute a percentage based on quantity tiers, and return a FunctionRunResult with targets of type cartLines and a percentage FixedAmount or Percentage value
  5. Set discountApplicationStrategy in the output (FIRST, MAXIMUM, or ALL) to control how multiple discount targets combine when more than one line qualifies
  6. Run `shopify app deploy` to upload the Function, then create an automatic discount via Admin GraphQL discountAutomaticAppCreate mutation referencing the Function ID; smoke-test by adding qualifying quantities to a cart

Known gotchas

Related routes

Build a Shopify Function for order-level discounts that applies a percentage off the entire order
ecommerce-ops · 6 steps · unrated
Create and deploy a Shopify Function for custom discount logic (order-level percentage off above a spend threshold) using the Discount API surface
shopify.dev · 5 steps · unrated
Build a Shopify Function for product discounts using Rust or JavaScript with a run.graphql input query
ecommerce-ops · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans