The Product Discount API enables you to create a new type of discount that is applied to particular product variants or
cart lines.
## Extension targets
The Product Discount API exposes the following [targets](/docs/apps/build/app-extensions/configure-app-extensions#targets):
| Target | Output type | Description |
| ------ | ----------- | ----------- |
| `purchase.product-discount.run` | [FunctionRunResult](#functionrunresult) | Outputs the product-level discount that should be applied to the cart |
## Input
The `RunInput` object is the complete schema that your function can receive as [input](/docs/apps/build/functions/input-output#input).
For a list of fields that the Product Discount API's `Input` object accepts, refer to [Input](/docs/api/functions/reference/product-discounts/graphql/input).
### Input Example
The following example shows an input query:
The following example shows the resulting input to the query:
## FunctionRunResult
The [`FunctionRunResult`][FunctionRunResult] object is the expected
[output](/docs/apps/build/functions/input-output#output) for the `purchase.product-discount.run` target.
### Targets
Each [`Discount`][Discount] returned in the output can have a collection of either
[`ProductVariantTarget`][ProductVariantTarget]s or [`CartLineTarget`][CartLineTarget]s, but not both.
This collection of [`Target`][Target] objects declare the cart line(s) to which the [`Discount`][Discount] will apply
its value. A [`CartLineTarget`][CartLineTarget] specifies a specific cart line, whereas a
[`ProductVariantTarget`][ProductVariantTarget] specifies a specific product variant, which could apply to one or more
cart lines for that product variant.
Additionally, each [`Target`][Target] has an optional `quantity` field which, when provided, limits the number of units
to which the [`Discount`][Discount] will apply its value.
Use [`CartLineTarget`][CartLineTarget]s when you want fine-grained control on specifically which cart lines will get
discounted. Alternatively, use [`ProductVariantTarget`][ProductVariantTarget] if your discounting strategy is based on
product variants, and you are not concerned which cart lines belonging to those product variants specifically get
discounted.
[Discount]: /docs/api/functions/reference/product-discounts/graphql/common-objects/discount
[Target]: /docs/api/functions/reference/product-discounts/graphql/common-objects/target
[ProductVariantTarget]: /docs/api/functions/reference/product-discounts/graphql/common-objects/productvarianttarget
[CartLineTarget]: /docs/api/functions/reference/product-discounts/graphql/common-objects/cartlinetarget
### Output Example
The following [`FunctionRunResult`][FunctionRunResult] includes a discount of 20% off for each cart line that has the
targeted product variant ID:
The following [`FunctionRunResult`][FunctionRunResult] includes a discount of $5 off for each cart line that has the
targeted product variant ID, up to a maximum of 2 items total among those cart lines (and $10 off):
If a discount should only apply to cart lines that have a particular attribute, then target the cart lines instead. In
the [example function input](/docs/api/functions/reference/product-discounts/graphql#input-example), there were two cart
lines with the same product variant. For example, you can discount only the cart line with the `Engraving Name`
attribute with following function output:
[FunctionRunResult]: /docs/api/functions/reference/product-discounts/graphql/functionrunresult