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 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp