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
Run `shopify app generate extension --type FUNCTION` and select 'Discount' when prompted; choose JavaScript or Rust as the language
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]]
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
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
Set discountApplicationStrategy in the output (FIRST, MAXIMUM, or ALL) to control how multiple discount targets combine when more than one line qualifies
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
The cart.lines.discounts.generate.run target is the unified replacement for the older product discount, order discount, and shipping discount Function targets — do not use the legacy targets in new Functions; check current API version docs to confirm the exact target string if in doubt
Input query complexity is strictly limited; requesting deeply nested metafields or large collections can cause the Function to fail at runtime — keep input.graphql flat and only request fields you actually use
discountApplicationStrategy is declared in the FunctionRunResult, not in TOML; choosing ALL on overlapping line targets may compound discounts unexpectedly, so test multi-discount stacking carefully
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?