> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dintero.com/llms.txt
> Use this file to discover all available pages before exploring further.

<AgentInstructions>

## Submitting Feedback

If you encounter incorrect, outdated, or confusing documentation on this page, submit feedback:

POST https://docs.dintero.com/feedback

```json
{
  "path": "/api-reference/rules/update-discount",
  "feedback": "Description of the issue"
}
```

Only submit feedback when you have something specific and actionable to report.

</AgentInstructions>

# Update Discount

> Update discount details.


**Caution**: Update of non-meta properties, properties that
changes requirement or limitation can create conflict with
the usage history of the discount.

Example is to change requirement.item.items, such change would
mean that purchases before the change would not be correcly
rewarded given the new version of the discount.

We recomment to limit the update of a discount to meta only
properties if the discount has previously been used in a
purchase.

Update on requirement `purchase_to` is only supported when
the new value that is after current value.

Update of requirement `purchase_from` and `reward` is not supported.

Update `discount.active` to toggle if an discount is active
and available for purchase.

Update `discount.private` to toggle if an discount is included
in public discount collection if given to all customers

scopes:
- admin:discounts
- write:discounts




## OpenAPI

````yaml /mintlify-docs/openapi/spec-discounts.yaml put /accounts/{aid}/discounts/rules/{did}
openapi: 3.0.0
info:
  title: Discounts API
  description: >
    API for managing discount for customers


    # Changelog

    All notable changes to the API.


    ## 2026-02-27


    > **update**: Add support for listing discount rules by state `active`,

    > `scheduled` and `completed`

    > - [GET /discounts/rules](#operation/aid_discounts_get)


    ## 2026-01-31


    > **new**: Add support for creating discount rule with `net_amount`
    requirement.

    > The new option enables support creating rules that works with receipts
    that

    > receive external discounts, where use will limit rule from being enabled

    > - [POST /discounts/rules](#operation/aid_discounts_post)

    > - [Example
    `requirement.net_amount`](#section/Discount-Examples/Net-Amount)


    ## 2024-09-01


    > **new**: Add support for creating discount with 

    > `limitation.dynamic_purchase_to_days`

    > - [POST /discounts/rules](#operation/aid_discounts_post)

    > - [Example
    `limitation.dynamic_purchase_to_days`](#section/Discount-Examples/Limitation:-dynamic-purchase-to)


    > **new**: Add support for updating `reward.base` when updating

    > a discount rule.

    > - [PUT /discounts/rules/{did}]((#operation/aid_discounts_did_put)


    ## 2024-04-01


    > **update**: Remove enum requirement for `enrolled_by.type` and

    > add support for more `receipt.customer.type` to support changes to the

    > customer user definition. See
    https://docs.dintero.com/customers-api.html#section/Changelog/2024-03-01

    > - [POST
    /v1/accounts/{aid}/discounts/available_for_receipt](#tag/use-discounts/operation/aid_discounts_available_for_receipt_post)


    ## 2023-12-01


    > **new**: Add support for `ANY_ITEM` when creating discount rule. The

    > new option makes it possible to create item rules that is valid for

    > any item but cannot be combined with other item rules (on same item)

    > - [POST /discounts/rules](#operation/aid_discounts_post)

    > ```json

    > {

    >   "requirement": {

    >     "item": {

    >       "items": [{"id":"ANY_ITEM"}],

    >     },

    >   --->8---------

    > }

    > ```


    > **new**: Add support for rules search.

    > - [POST
    /v1/accounts/{aid}/discounts/search/rules](#tag/rules/operation/aid_discounts_rules_search_post)


    ## 2023-11-01


    > **new**: Support creating rules with `reward.values`. The new option

    > make it possible to create a single rule that can give different

    > rewards based on purchased items, replacing the need to create a rule

    > for each reward.

    > - [POST
    /v1/accounts/{aid}/discounts/rules](#tag/rules/operation/aid_discounts_post)

    > - [Reward values example](#section/Discount-Examples/Reward-values)


    ## 2023-07-01


    > - **new** Support creating bonus reward rules via `reward.effect=bonus`.

    > Bonus given on a purchase will be included in receipt

    > `discounts.[].refs[].bonus` and `items.[].bonus_lines`

    >

    > - [POST
    /v1/accounts/{aid}/discounts/rules](#tag/rules/operation/aid_discounts_post)

    > - [POST
    /v1/accounts/{aid}/discounts/available_for_receipt](#tag/use-discounts/operation/aid_discounts_available_for_receipt_post)


    ## 2022-03-01


    > - **new** Support private metadata properties in discount rules.

    > Metadata prefixed with `dintero:exclude:public:` will now be

    > excluded when listing public rules


    ## 2021-10-01


    > Add support for specifying
    `limitation.discount_activation[*].type=deactivate_if_discount_active`.

    > Use the new option to limit the activation of a discount based on other
    active

    > discounts

    > - [POST /discounts/rules](#operation/aid_discounts_post)


    ## 2021-09-01


    > **DEPRECATE**: `requirement.store_id` <br/>

    > Use the `requirement.store.id` property to limit discount on store id.

    > - [POST /discounts/rules](#operation/aid_discounts_post)


    ## 2021-07-01


    > Add support for specifying `requirement.customer.attributes.[property]`

    when creating new discount rules.

    > - [POST /discounts/rules](#operation/aid_discounts_post)



    ## 2020-08-01


    > Add support for campaigns, group rules by campaign_id

    > - [POST /discounts/campaigns](#operation/aid_discounts_campaigns_post)


    ## 2020-05-01


    > Add support for `offering_constraint_id` when giving discount to one

    > or more customers. The new optional can be used to constrain how many

    > times the customer will receive the discount.

    > - [POST
    /discounts/rules/{did}/customers](#operation/aid_discounts_did_customers_post)


    ## 2020-03-10


    > Extend discount statistics with `current_stamp`

    > - [GET
    /discounts/customers/{customer_id}/refs/{ref_id}](#operation/aid_discounts_customer_cid_get_ref_id)

    > - [GET
    /discounts/rules/{did}/usages](#operation/aid_discounts_did_usages_get)

    > - [GET
    /discounts/customers/{customer_id}/rules](#operation/aid_discounts_customer_cid_get)

    >


    ## 2020-01-31


    > Add support for adding requirements for MCC ranges, and currencies in
    discounts.

    > - [POST /discounts/rules]((#operation/aid_discounts_post)

    > - [PUT /discounts/rules/{did}]((#operation/aid_discounts_did_put)


    > Add support for adding usage ref (usage, stamp, amount) to

    > a customer discount ref.

    > - [POST
    /discounts/customers/{customer_id}/refs/{ref_id}](#operation/aid_discounts_customer_cid_post_ref_id)

    > - [GET
    /discounts/customers/{customer_id}/refs/{ref_id}](#operation/aid_discounts_customer_cid_get_ref_id)


    > Add support for discount rules with `discount_code`.

    > The `discount_code` must be included in the purchase, either in the

    > new `discount_code` property or as an item, where the item id is set

    > to the `discount_code`.

    > - [POST /discounts/public/rules](#operation/aid_discounts_post)

    > - [POST
    /discounts/available_for_receipt](#operation/aid_discounts_available_for_receipt_post)


    > Add support for `no_customer_id` query parameter when

    > listing public discount rules.

    > - [GET /discounts/public/rules](#operation/aid_discounts_public_get)


    ## 2019-12-31


    > Add support for specifying `requirement.store` when creating

    > new discount rules.

    > - [POST /discounts/rules](#operation/aid_discounts_post)


    > Add support for giving discounts on purchase with no `customer_id`.

    > - [POST
    /discounts/available_for_receipt](#operation/aid_discounts_available_for_receipt_post)

    > - [POST
    /discounts/rules/{did}/customers](#operation/aid_discounts_did_customers_post)


    > Add support for updating rules `requirement.purchase_to`.

    > - [PUT /discounts/rules/{did}](#operation/aid_discounts_did_put)


    ## 2019-10-31


    > Change minumum number of mixes in a discount rule from

    > 2 to 1

    > - [POST /discounts/rules](#operation/aid_discounts_post)


    ## 2019-07-31


    > Exclude statistics, usage and stamp count and more

    > in response from:

    > - [GET
    /discounts/rules/{did}/customers](#operation/aid_discounts_did_customers_get)


    > Add new endpoint for retrieving discount usages

    > - [GET
    /discounts/rules/{did}/usages](#operation/aid_discounts_did_usages_get)


    ## 2019-06-31


    > The scope required for accessing endpoint has changed,

    > we will continue to support the old scopes but they was removed from

    > the documentation


    ## 2019-04-31


    > Include statistics, usage and stamp count and more

    > in response from:

    > - [GET
    /discounts/customers/{customer_id}/rules](#operation/aid_discounts_customer_cid_get)

    > - [GET
    /discounts/rules/{did}/customers](#operation/aid_discounts_did_customers_get)


    > *deprecate* the `statistics.used` property, replaced by
    `statistics.usage`.


    > *Moved* the `debit_balance` property into `statistics.usage`.


    > Add new `mixes` property to the discount requirement item.

    > The new property can be used to define Mix & Match discounts, discount

    > that requires multiple items to be purchase to enable the reward.

    > - [POST /discounts/rules](#operation/aid_discounts_post)


    ## 2019-01-31


    > Add new `private` property to the discount rule object.

    > A private discount will be excluded from public discount

    > collection if the rule is given to all customers.

    > - [POST /discounts/rules](#operation/aid_discounts_post)

    > - [PUT /discounts/rules/{did}](#operation/aid_discounts_did_put)

    > - [GET /discounts/public/rules](#operation/aid_discounts_public_get)


    > Add new endpoint for getting details about a

    >  discount claim.

    > - [GET
    /discounts/available_for_receipt/claims/{claim_id}](#operation/aid_discounts_available_for_receipt_get_claim)


    > Increase maximum `limit` value accepted by endpoint:

    > - [GET
    /discounts/rules/{did}/customers](#operation/aid_discounts_did_customers_get)


    ## 2018-11-26


    > Extend the `discount.limitation` with

    > `discount_eligible`, an optional property for limiting what

    > items in a purchase is eligible for the rule.


    > Extend the `discount.limitation` with

    > `discount_combination`, an optional property for limiting how

    >  many other discount rules the rule can be combined with.


    > Extend the `discount.limitation` with `blacklist`,

    > an optional property for blacklisting items by id or group, items

    > not eligible for discount.


    ## 2018-06-04


    > Extend support for discount customer requirement.

    > - [POST /discounts/rules](#operation/aid_discounts_post)


    > Add support for claim collection

    > - [GET
    /discounts/available_for_receipt/claims](#operation/aid_discounts_available_for_receipt_get_claims)


    > Add support for inactive discount by new `active`

    > property on discount.

    > - [POST /discounts/rules](#operation/aid_discounts_post)

    > - [PUT /discounts/rules/{did}](#operation/aid_discounts_did_put)

    > - [GET /discounts/rules](#operation/aid_discounts_get)


    > An inactive discount will not be included in response from

    > - [GET /discounts/public/rules](#operation/aid_discounts_public_get)

    > - [GET
    /discounts/customers/{customer_id}/rules](#operation/aid_discounts_customer_cid_get)


    > Add new endpoint for listing customer a discount

    > has been given to.

    > - [GET
    /discounts/rules/{did}/customers](#operation/aid_discounts_did_customers_get)


    ## 2018-04-11


    > Extend support for update of discount rule to allow

    > update of limitation and requirement

    > Include `updated_by` property container the user/client that last updated

    > the discount rule.

    > - [PUT /discounts/rules/{did}](#operation/aid_discounts_did_put)


    > Add support for filtering discounts by `state`, `since_datetime`,
    `purchase_from`

    > and `purchase_to`

    > - [GET /discounts/rules](#operation/aid_discounts_get)


    ## 2018-02-15


    > Change default item.quantity requirement from `1` to `0`.

    > Allows discount on items where quantity is in weigth/volume and value is <
    1

    > by default.


    > Add minimum length for token token_id/type/value/customer_id

    > - [POST /discounts/events](#operation/aid_discounts_events_post)


    > Add new reward type `discount_debit`


    ## 2018-02-02


    > Add `links` and `metadata` property to the discount.

    >  Support adding links related to the discount and any key/value metadata


    ## 2017-12-04


    > Add `type` property to the discount.

    > The value is calculated from the discount.requirement,

    > stating if the discount is given on the receipt or

    > limited to specific items.


    > Change type of properties to support decimal values.

    > - *discount.reward.value* *discount.requirement.item.quantity*


    > Rename reward type enums.

    > - *discount_total_amount* => *discount_amount*

    > - *discount_percent_amount* => *discount_percent*

    > - *discount_new_item_price* => *discount_item_new_price*

    > - *discount_item* => *discount_item_quantity*

    > - *discount_item_percent_amount* => *discount_item_percent*


    > Define required properties for a discount requirement.

    > - *requirement.purchase_from* *requirement.purchase_to*


    ## 2017-11-22


    > Add support for discount rule with

    > customer.status requirement.



    # Bonus Examples


    Short bonus rules examples for the supported reward types


    ## Bonus


    Get 15000 in bonus for purchase at store if total is over 50000

        {
            "limitation": {
                "discount_reward_usage": 1
            },
            "requirement": {
                "gross_amount": 50000,
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z",
                "store_ids": ["sc029"]
            },
            "reward": {
                "type": "discount_amount",
                "value": 15000,
                "effect": "bonus"
            }
        }

    # Discount Examples


    Short discount rules examples for the supported reward types


    ## Amount


    Get 15000 in discount for purchase at store if total is over 50000

        {
            "limitation": {
                "discount_reward_usage": 1
            },
            "requirement": {
                "gross_amount": 50000,
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z",
                "store_ids": ["sc029"]
            },
            "reward": {
                "type": "discount_amount",
                "value": 15000
            }
        }

    ## Net Amount


    Get 15000 in discount for purchase at store if total net amount is over
    50000


    > Use `net_amount` over `gross_amount` if the requirement should be

    > dependent on external discount that reduces the `net_amount` before
    discount

    > is calculated

        {
            "limitation": {
                "discount_reward_usage": 1
            },
            "requirement": {
                "net_amount": 50000,
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z",
                "store_ids": ["sc029"]
            },
            "reward": {
                "type": "discount_amount",
                "value": 15000
            }
        }

    ## % one-time


    Get 25% discount for one purchase that includes the item 714118

        {
            "limitation": {
                "discount_repeat_usage": 1
            },
            "requirement": {
                "item": {
                    "items": [{"id": "714118"}]
                },
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z"
            },
            "reward": {
                "type": "discount_percent",
                "value": 25
            }
        }

    ## % only currencies


    25 % discount on tex-mex items if purchase currency is `NOK`.

        {
            "requirement": {
                "item": [{"group_id": "tex-mex"}],
                "purchase_from": "2020-01-03T09:00:04Z",
                "purchase_to": "2020-01-03T22:00Z",
                "currencies": ["NOK"]
            },
            "reward": {
                "type": "discount_percent",
                "value": 25
            }
        }

    ## % anything-but currencies


    25% discount on tex-mex items if purchase currency is anything but `NOK`.

        {
            "requirement": {
                "item": [{"group_id": "tex-mex"}],
                "purchase_from": "2020-01-03T09:00:04Z",
                "purchase_to": "2020-01-03T22:00Z",
                "currencies": [{"anything-but": ["NOK"]}]
            },
            "reward": {
                "type": "discount_percent",
                "value": 25
            }
        }

    ## % discount_code


    25% discount on tex-mex items when using discount_code `TACOFREDAG`.

        {
            "requirement": {
                "item": [{"group_id": "tex-mex"}],
                "discount_code": "TACOFREDAG",
                "purchase_from": "2020-01-03T09:00:04Z",
                "purchase_to": "2020-01-03T22:00Z"
            },
            "reward": {
                "type": "discount_percent",
                "value": 25
            }
        }

    ## New price - one-time


    Discount calculated from the `original price - new price`

        {
            "limitation": {
                "discount_repeat_usage": 1
            },
            "requirement": {
                "item": {
                    "items": [{"id": "714118"}]
                },
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z"
            },
            "reward": {
                "type": "discount_item_new_price",
                "value": 2500
            }
        }

    ## New price - mix & match


    All items in a mix will get the new price and discount calculated

    from their original prices and new price

        {
            "limitation": {
                "discount_reward_usage": 1
            },
            "requirement": {
                "item": {
                    "mixes": [
                        {"items":[{"id": "cola"}], "quantity":1, "reward_eligible": true},
                        {"items":[{"id": "sprite"}], "quantity":1, "reward_eligible": true}
                    ]
                },
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z"
            },
            "reward": {
                "type": "discount_item_new_price",
                "value": 3000
            }
        }

    ## New price - mix & match total


    New total price for the items in the mix. Discount calculated from original

    prices and the new total.

        {
            "limitation": {
                "discount_reward_usage": 1
            },
            "requirement": {
                "item": {
                    "mixes": [
                        {"items":[{"group_id": "trampoline"}], "quantity":1, "reward_eligible": true},
                        {"items":[{"group_id": "sikkerhetsnett"}], "quantity":1, "reward_eligible": true}
                    ]
                },
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z"
            },
            "reward": {
                "type": "discount_mix_new_price",
                "value": 255990
            }
        }

    ## Quantity - 3 for 2


    Give the cheapest for free

        {
            "requirement": {
                "item": {
                    "items": [{"id": "714118"}],
                    "quantity": 3
                },
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z"
            },
            "reward": {
                "type": "discount_item_quantity",
                "value": 1
            }
        }

    ## Quantity - mix & match


    Get one free if mix is in purchase. Get colgate for free if

    purchased with any soda

        {
            "requirement": {
                "item": {
                    "mixes": [
                        {"items": [{"id":"solo", "id":"cola"}], "quantity":1, "reward_eligible": false},
                        {"items": [{"group_id": "colgate"}], "quantity":1, "reward_eligible": true}
                    ]
                },
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z"
            },
            "reward": {
                "type": "discount_item_quantity",
                "value": 1
            }
        }

    ## Item % - stamp


    Get 50% discount on every 5 purchase done within 100 days

        {
            "limitation": {
                "stamp_expire_days": 100
            },
            "requirement": {
                "item": [{"id": "cola"}],
                "stamp": 5,
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z"
            },
            "reward": {
                "type": "discount_item_percent",
                "value": 50
            }
        }

    ## Debit - min purchase


    Get 20000 (initial) in debit discount, can be used

    over multiple purchase where the total amount is over 10000.

        {
            "requirement": {
                "gross_amount": 10000,
                "purchase_from": "2018-01-29T11:44:04Z",
                "purchase_to": "2018-02-24T12:00Z"
            },
            "reward": {
                "type": "discount_debit",
                "value": 20000
            }
        }

    ## Reward values


    Reward values are supported for reward types:

     - discount_amount
     - discount_item_new_price
     - discount_item_percent
     - discount_percent

    Use reward values to combine product rewards into a single discount rule.


    The example will calculate reward so items of group id `G1` get a new price

    of `2000` and item with id `714118`

    will get new price of 2500

        {
            "requirement": {
                "item": {
                    "items": [{"id": "714118"}, {"group_id": "G1"}],
                    "quantity": 1
                 },
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z"
            },
            "reward": {
                "type": "discount_item_new_price",
                "value": 2500
                "values": [
                    {
                        "items": [{ "group_id": "G1" }],
                        "value": 2000
                    }
                ]
            }
        }

    ## Limitation - reward & repeat


    Limit new price discount to max 3 items and 1 purchase.

    Note that `requirement.item.quantity` must be set to enable

    the `discount_reward_usage` limitation.

        {
            "limitation": {
                "discount_repeat_usage": 1,
                "discount_reward_usage": 3
            },
            "requirement": {
                "item": {
                    "items": [{"id": "714118"}],
                    "quantity": 1
                },
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z"
            },
            "reward": {
                "type": "discount_item_new_price",
                "value": 2500
            }
        }

    ## Limitation: purchase time


    Limit discount to specific day of the week, e.g

    receive 50 % in discount on Tuesdays

        {
            "limitation": {
                "discount_hours": {
                    "hours": [{
                    "day": "tue",
                    "start": "10:00",
                    "end": "23:00"
                    }],
                    "timezone": "Europe/Oslo"
                }
            },
            "requirement": {
                "item": {
                    "items": [{"id": "714118"}]
                },
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z"
            },
            "reward": {
                "type": "discount_item_percent",
                "value": 50
            }
        }

    ## Limitation: combination


    Limit discount with blacklist, combination and purchase not

    received other discounts

        {
            "limitation": {
                "discount_combination": 0,
                "discount_eligible": "receipt_no_discount",
                "blacklist": [{"group_id": "tobacco"}]
            },
            "requirement": {
                "item": {
                    "items": [{"id": "*"}]
                },
                "purchase_from": "2017-11-29T11:44:04Z",
                "purchase_to": "2017-12-24T12:00Z"
            },
            "reward": {
                "type": "discount_item_percent",
                "value": 10
            }
        }

    ## Limitation: dynamic purchase to


    Limit the `purchase_to` to a time calculated from when the discount was
    given to

    a customer


    > E.g. a discount rule that "never" expires, but it will only be available

    > for the customer for 30 days when given

        {
            "limitation": {
                "dynamic_purchase_to_days": 30
            },
            "requirement": {
                "item": {
                    "items": [{"id": "*"}]
                },
                "purchase_from": "2025-04-30T08:47:34.344Z",
                "purchase_to": "2099-04-30T08:47:34.344Z"
            },
            "reward": {
                "type": "discount_item_percent",
                "value": 10
            }
        }
  contact:
    name: API Integration Support
    email: integration@dintero.com
  version: 1.0.0
  license:
    name: UNLICENSED
    url: https://dintero.com
servers:
  - url: https://api.dintero.com/v1
security:
  - JWT: []
paths:
  /accounts/{aid}/discounts/rules/{did}:
    put:
      tags:
        - rules
      summary: Update Discount
      description: |
        Update discount details.


        **Caution**: Update of non-meta properties, properties that
        changes requirement or limitation can create conflict with
        the usage history of the discount.

        Example is to change requirement.item.items, such change would
        mean that purchases before the change would not be correcly
        rewarded given the new version of the discount.

        We recomment to limit the update of a discount to meta only
        properties if the discount has previously been used in a
        purchase.

        Update on requirement `purchase_to` is only supported when
        the new value that is after current value.

        Update of requirement `purchase_from` and `reward` is not supported.

        Update `discount.active` to toggle if an discount is active
        and available for purchase.

        Update `discount.private` to toggle if an discount is included
        in public discount collection if given to all customers

        scopes:
        - admin:discounts
        - write:discounts
      operationId: aid_discounts_did_put
      parameters:
        - $ref: '#/components/parameters/accountId'
        - $ref: '#/components/parameters/discountId'
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                campaign_id:
                  description: |
                    The campaign the rule belongs to, use `null` to remove
                    the rule from the campaign.
                  nullable: true
                  type: string
                active:
                  description: |
                    the discount is active and can be available
                    for purchase
                  type: boolean
                  default: true
                private:
                  description: |
                    the discount is private and will not be included in
                    public discount collection
                  type: boolean
                  example: false
                links:
                  $ref: '#/components/schemas/Links'
                limitation:
                  $ref: '#/components/schemas/Limitation'
                requirement:
                  allOf:
                    - $ref: '#/components/schemas/BaseRequirement'
                    - properties:
                        purchase_to:
                          type: string
                          format: date-time
                          description: |
                            New value must be after current
                reward:
                  type: object
                  properties:
                    base:
                      $ref: '#/components/schemas/RewardBase'
                description:
                  type: string
                  example: Gjør et Stablestol kupp!
                metadata:
                  type: object
                  maxProperties: 10
                  description: |
                    Additional metadata about the discount
                  example:
                    campaign_id: V101
                    is_featured: true
                name:
                  type: string
                  example: Spar 100,-
                receipt_text:
                  type: string
                  description: |
                    Text that should be used when displaying
                    the discount, e.g. on receipt
                  example: Mai Salg
        description: Discount properties to update
        required: true
      responses:
        '200':
          description: Discount Updated
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Discount'
                  - $ref: '#/components/schemas/Statistics'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/AccessForbidden'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '500':
          $ref: '#/components/responses/ServerError'
      security:
        - JWT: []
components:
  parameters:
    accountId:
      name: aid
      description: |
        An id that uniquely identifies the account.
      in: path
      required: true
      schema:
        type: string
        format: ^[PT]{1}\d{8}$
        minLength: 9
        maxLength: 9
    discountId:
      name: did
      description: An UUID that uniquely identifies the discount
      in: path
      required: true
      schema:
        type: string
        format: uuid
  schemas:
    Links:
      description: Links to resources related to the discount
      type: array
      example:
        - href: >-
            https://example.dintero.com/c/photos/2018/6_20_thumbnail_discount_image.png
          rel: thumbnail_discount_image
        - href: >-
            https://example.dintero.com/c/photos/2018/6_20_medium_discount_image.png
          rel: medium_discount_image
        - href: >-
            https://example.dintero.com/shop?utm_source=dintero&utm_medium=email&utm_campaign=spring-summer
          rel: webshoop
        - href: https://example.dintero.com/newsletter/2018.pdf
          rel: newletter
          type: application/pdf
      items:
        type: object
        maxItems: 10
        required:
          - href
        properties:
          href:
            description: The URL of the link.
            type: string
            format: uri
          rel:
            description: |
              Specifies the relationship between the discount and the link

              Following `rel` values are reserved for specific usage

                - thumbnail_discount_image: link to discount image
                - medium_discount_image: link to discount image
                - large_discount_image: link to discount image
                - webshop: link to site where the discount may be used
            type: string
          type:
            type: string
            description: Specifies the media type of the link
    Limitation:
      type: object
      properties:
        dynamic_purchase_to_days:
          type: number
          format: int32
          minimum: 1
          description: >
            Limit the `purchase_to` to the time added to a customer + the days


            The customer discount rule `purchase_to` will be set to the minimum

            of `requirement.purchase_to` and `now +
            limitation.dynamic_purchase_to_days`
        discount_activation:
          type: array
          description: |
            Dynamically control if the discount should be active.
          items:
            minItems: 1
            maxItems: 1
            type: object
            required:
              - type
              - value
            properties:
              type:
                type: string
                description: >
                  - `deactivate_if_discount_active`: The discount is deactivated
                  if
                    the value match the `id` of another active discount
                    available for the purchase
                enum:
                  - deactivate_if_discount_active
              value:
                type: string
                description: |
                  Value given the type
        discount_hours:
          type: object
          description: |
            Limit the discount to hours of the day
          required:
            - hours
          properties:
            timezone:
              description: |
                The timezone identifier for the hour start/end, see
                https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
                for examples. DST is handled when using a Timezone with DST.
              default: Europe/Oslo
              type: string
            hours:
              description: |
                an array of periods, day and time when discount will be
                available. Multiple periods for one day is accepted.
                Any hour of purchase is accepted if the array is empty.
              type: array
              items:
                type: object
                required:
                  - day
                  - start
                  - end
                properties:
                  day:
                    type: string
                    enum:
                      - mon
                      - tue
                      - wed
                      - thu
                      - fri
                      - sat
                      - sun
                  start:
                    type: string
                    pattern: ^([01]?[0-9]|2[0-3]):[0-5][0-9]$
                    example: '10:00'
                  end:
                    type: string
                    pattern: ^([01]?[0-9]|2[0-3]):[0-5][0-9]$
                    example: '20:00'
        discount_reward_usage:
          type: integer
          description: |
            Limit the number of rewards to be given in a purchase
            where multiple receipt items match the requirement
          example: 1
          default: -1
        discount_combination:
          type: integer
          description: |
            Limit how many other discounts can be combined in a purchase
            where multiple discounts are applicable.
          default: -1
          enum:
            - -1
            - 0
        discount_eligible:
          type: string
          description: |
            Limit what items in the purchase is eligible for this discount
          enum:
            - item_eligible_for_discount
            - item_eligible_for_discount_no_discount
            - receipt_no_discount
          default: item_eligible_for_discount
        discount_repeat_usage:
          type: integer
          description: |
            Limit how many purchases the discount can be used
          default: -1
        stamp_expire_days:
          type: integer
          description: |
            Number of days between first and last (exceeding count) stamp
            where reward will be given
          example: 100
          default: -1
        blacklist:
          type: array
          description: |
            items not eligible for discount.
          items:
            $ref: '#/components/schemas/Item'
          minItems: 1
    BaseRequirement:
      type: object
      description: |
        Discount base requirement
      properties:
        customer:
          $ref: '#/components/schemas/CustomerRequirement'
        item:
          type: object
          properties:
            quantity:
              type: number
              description: |
                minimum number of items
              default: 0
              minimum: 0
            mixes:
              type: array
              minItems: 1
              description: >
                Required mix items for the discount.


                A purchase must include `all` the items to fulfill the
                `item.mixes`

                requirement.
              items:
                $ref: '#/components/schemas/ItemMixProperty'
            items:
              type: array
              description: >
                Required items for the discount


                A purchase can include `any` of the items to fulfill the
                `item.items`

                requirement.


                The values contols if the reward is given on the receipt (all
                items) or

                if they are limited to matching items


                **Receipt**

                - A rule with no items or items with only wildcard items


                **Item**

                - A rule with one or more items (except wildcard)

                - A rule with a single item `{"id": "ANY_ITEM"}` in items
              items:
                $ref: '#/components/schemas/Item'
              minItems: 1
        store_ids:
          type: array
          description: |
            `DEPRECATED`: [@since 2021-09-01](#section/Changelog/2021-09-01)
          items:
            type: string
            example: sc029
        gross_amount:
          type: integer
          description: |
            Minimum gross amount on purchase.
            Monetary amount in smallest unit for the currency
          default: 0
        net_amount:
          type: integer
          description: |
            Minimum net amount on purchase (amount after existing discounts).
            Monetary amount in smallest unit for the currency
          default: 0
        currencies:
          description: >
            List of valid currencies, or `[{"anything-but": ["NOK"]}]` to
            exclude currencies.

            Currency format is the three-character [ISO-4217
            currency](https://en.wikipedia.org/wiki/ISO_4217).
          type: array
          items:
            anyOf:
              - type: object
                properties:
                  anything-but:
                    type: array
                    items:
                      type: string
                      example: NOK
              - type: string
                example: NOK
        stamp:
          type: integer
          description: |
            Stamp count required for the reward
          example: 5
        discount_code:
          type: string
          description: |
            A code required for the reward. The purchase must include the
            promotion code in the `receipt.discount_code` property or as
            an `receipt.item` where the `item.id` is the promotion code.
          example: TACO
        store:
          $ref: '#/components/schemas/StoreRequirement'
    RewardBase:
      type: string
      description: |
        Let the discount reward be calculated from net or gross price.
        Not applicable for `discount_item_new_price`

        *Example*:
          item A à 100,- NOK with existing rebate of 20,-

          - 10% net reward is 10% of 80,- : 8,-
          - 10% gross reward is 10% of 100,- : 10,-

          * *net*: `gross - "any existing discounts"`
          * *gross*: `"total expense amount, including taxes"`
      default: gross
      enum:
        - net
        - gross
    Discount:
      required:
        - requirement
        - reward
      properties:
        id:
          type: string
          format: uuid
          description: |
            An UUID that uniquely identifies the resource
          readOnly: true
        created_at:
          type: string
          format: date-time
          description: |
            The date-time when the resource was created
          readOnly: true
        created_by:
          type: string
          example: 1c92f7e1-2897-4d46-bdcc-c127a914fb4e
          description: |
            The ID of the user/client created the resource
          readOnly: true
        updated_at:
          type: string
          format: date-time
          description: |
            The date-time when the resource was last updated
          readOnly: true
        deleted_by:
          type: string
          example: 1c92f7e1-2897-4d46-bdcc-c127a914fb4e
          description: |
            The ID of the user/client created the resource
          readOnly: true
        deleted_at:
          type: string
          format: date-time
          readOnly: true
        campaign_id:
          type: string
          description: |
            The campaign the rule belongs to
        active:
          description: |
            the discount is active and can be available
            for purchase (if given to any or all customers)
          type: boolean
          default: true
        private:
          description: |
            the discount will be excluded from  public discount collection
            (GET /discounts/public/rules).
          type: boolean
          default: false
        updated_by:
          type: string
          example: 3d1e4824-5474-48e7-a369-4f603fa4c5b8
          description: |
            The ID of the user/client that last updated the resource
          readOnly: true
        type:
          type: string
          description: >-
            The discount base type * `receipt` discount is given on receipt *
            `item` discount is given to items
          enum:
            - item
            - receipt
          readOnly: true
        name:
          type: string
          example: Spar 100,-
        receipt_text:
          type: string
          description: |
            Text that should be used when displaying
            the discount, e.g. on receipt
          example: Mai Salg
        visible_from:
          type: string
          format: date-time
          description: |
            Make the discount visible to the customer from
            given date. Default behavior is to only return
            discount to the customer where the current time
            is between purchase_from and purchase_to
        description:
          type: string
          example: Gjør et Stablestol kupp!
        limitation:
          $ref: '#/components/schemas/Limitation'
        requirement:
          $ref: '#/components/schemas/Requirement'
        reward:
          $ref: '#/components/schemas/Reward'
        metadata:
          type: object
          maxProperties: 10
          description: >
            Additional metadata about the discount


            Metadata prefixed with `dintero:exclude:public:` will

            be excluded when listing the rules from the public endpoint


            - [GET
            /v1/accounts/{aid}/discounts/public/rules](#operation/aid_discounts_public_get)


            and included in all other endpoints that returns discount rules
          example:
            campaign_id: V101
            is_featured: true
            dintero:private_text:kind: Gold
        links:
          $ref: '#/components/schemas/Links'
    Statistics:
      type: object
      properties:
        statistics:
          type: object
          properties:
            stamp:
              type: integer
              description: |
                total stamp collected
            used:
              type: integer
              description: |
                **deprecated** number of times the discount has been used
              example: 28
            usage:
              type: integer
              description: number of times the discount has been used
              example: 28
            amount:
              type: integer
              description: total reward given
              example: 280000
            debit_balance:
              type: integer
              description: |
                the discount debit balance, only applicable if
                discount reward type is `discount_debit`
              example: 12350
    Item:
      type: object
      properties:
        id:
          type: string
          example: b714118
        group_id:
          type: string
          example: B1
    CustomerRequirement:
      type: object
      properties:
        addresses:
          type: array
          description: >-
            Require customer to have one or more addresses matching the
            properties. All properties defined must match a single address.
          items:
            type: object
            minItems: 1
            maxItems: 5
            properties:
              country:
                type: array
                example:
                  - 'NO'
                items:
                  type: string
                  minItems: 1
                  maxItems: 5
              postal_code:
                type: array
                example:
                  - '0349'
                items:
                  type: string
                  minItems: 1
                  maxItems: 5
              postal_place:
                type: array
                example:
                  - Oslo
                items:
                  type: string
                  minItems: 1
                  maxItems: 5
              custom_type:
                type: array
                example:
                  - offsite
                items:
                  type: string
                  minItems: 1
                  maxItems: 5
              type:
                type: array
                example:
                  - custom
                items:
                  type: string
                  minItems: 1
                  maxItems: 5
        company:
          type: object
          description: |
            Require customer to be a company matching all properties defined.
          properties:
            bussiness_name:
              type: array
              example:
                - TKP tech AS
              items:
                type: string
                minItems: 1
                maxItems: 5
            department:
              type: array
              example:
                - production
                - research
              items:
                type: string
                minItems: 1
                maxItems: 5
            industry:
              type: array
              example:
                - J62.0.1
                - J62.0.2
              items:
                type: string
                minItems: 1
                maxItems: 5
            number_of_employees:
              type: array
              example:
                - '20'
              items:
                type: string
                minItems: 1
                maxItems: 5
            organization_number:
              type: array
              example:
                - 123456789MVA
              items:
                type: string
                minItems: 1
                maxItems: 5
            website:
              type: array
              example:
                - https://dintero.com
              items:
                type: string
                minItems: 1
                maxItems: 5
        date_of_birth:
          type: array
          example:
            - '1990-09-20'
            - '1990-05-10'
          items:
            type: string
            minItems: 1
            maxItems: 5
        enrolled_by:
          type: object
          properties:
            type:
              type: array
              example:
                - url
              items:
                type: string
                minItems: 1
                maxItems: 5
            value:
              type: array
              example:
                - https://mypage.example.dintero.com
              items:
                type: string
                minItems: 1
                maxItems: 5
        favorite_store:
          type: array
          example:
            - sc029
          items:
            type: string
            minItems: 1
            maxItems: 5
        first_name:
          type: array
          example:
            - John
          items:
            type: string
            minItems: 1
            maxItems: 5
        gender:
          type: array
          example:
            - male
          items:
            type: string
            minItems: 1
            maxItems: 5
        last_name:
          type: array
          example:
            - Doe
          items:
            type: string
            minItems: 1
            maxItems: 5
        marketing_consent:
          type: object
          properties:
            email:
              type: object
              properties:
                consent:
                  type: array
                  example:
                    - 'true'
                  items:
                    type: string
                    minItems: 1
                    maxItems: 5
            sms:
              type: object
              properties:
                consent:
                  type: array
                  example:
                    - 'true'
                  items:
                    type: string
                    minItems: 1
                    maxItems: 5
        status:
          type: array
          example:
            - vip
          description: |
            limit discount to only receipt where customer status
            is included in the receipt and match one of the status
            values required by the discount
          items:
            type: string
            minItems: 1
            maxItems: 5
        term:
          type: object
          properties:
            id:
              type: array
              items:
                type: string
                minItems: 1
                maxItems: 5
        type:
          type: array
          items:
            type: string
            minItems: 1
            maxItems: 5
        attributes:
          type: object
          description: >
            Limit discount to only receipt where customer attributes are
            included

            and match one of the values required by the discount
          additionalProperties:
            type: array
            items:
              type: string
            minItems: 1
            maxItems: 5
    ItemMixProperty:
      type: object
      description: |
        Use mix in case where all items are required in one purchase.

        A reward will be eligible to all items in the mix that
        has `mix.reward_eligible=true`
      required:
        - quantity
        - reward_eligible
      properties:
        items:
          description: |
            Acceptable items for the mix "item" (`any`). No wildcard `*` is
            accepted.
          type: array
          example:
            - id: b714118
            - group_id: g4
          items:
            type: object
            minItems: 1
            properties:
              id:
                type: string
                example: b714118
                pattern: ^(\*.+|(?!\*).*)$
              group_id:
                type: string
                pattern: ^(\*.+|(?!\*).*)$
                example: g4
        quantity:
          type: number
          description: |
            minimum quantity of given item (match by id or group) by the mix
          minimum: 0
        reward_eligible:
          type: boolean
          description: >
            The item will be eligible for discount when calculating the reward

            Example: The value of `discount_item_new_price` reward will be the

            total price of all items in a mix that has the applicable set to
            `true`
    StoreRequirement:
      type: object
      properties:
        id:
          type: array
          items:
            type: string
            example: sc029
        name:
          type: array
          description: |
            name of the store, aka trade name of the store
          items:
            type: string
            example: SC Oslo
        business_name:
          type: array
          description: |
            Official name of the person or entity that owns the store.
          items:
            type: string
            example: SC Oslo AS
        address:
          type: object
          description: >-
            Require customer to have one or more addresses matching the
            properties. All properties defined must match a single address.
          properties:
            country:
              type: array
              example:
                - 'NO'
              items:
                type: string
                minItems: 1
                maxItems: 5
            postal_code:
              type: array
              example:
                - '0349'
              items:
                type: string
                minItems: 1
                maxItems: 5
            postal_place:
              type: array
              example:
                - Oslo
              items:
                type: string
                minItems: 1
                maxItems: 5
        chain:
          type: array
          items:
            type: string
            example: SuperChain
        email:
          type: array
          items:
            type: string
            example: contact@superchain.com
        gln:
          type: array
          items:
            type: string
            example: '5790001398644'
        organization_number:
          type: array
          items:
            type: string
            example: 123456789MVA
        phone_number:
          type: array
          items:
            type: string
            example: '+4738260107'
        mcc:
          type: array
          description: |
            A four-digit Merchant Category Code (MCC) for the store
            [ISO 18245:2003](https://www.iso.org/standard/33365.html)
          items:
            type: string
            format: iso-18245
            example: 5814
        mcc_ranges:
          type: array
          description: |
            Ranges of MCC codes to accept the discount for.
            Multiple ranges are possible.
            Prefer `mcc` if not a range.
          items:
            type: object
            required:
              - start
              - end
            properties:
              start:
                type: string
                format: iso-18245
                example: 5814
                minimum: 4
                maximum: 4
                pattern: ^\d{4}$
              end:
                type: string
                format: iso-18245
                example: 5815
                minimum: 4
                maximum: 4
                pattern: ^\d{4}$
        bax:
          type: array
          description: |
            Merchant number associated with the stores
            payment terminal
          items:
            type: string
            example: '102603'
        terminal_id:
          type: array
          description: |
            Id to a specific point-of-sale (POS) terminal
            or workstation
          items:
            type: string
            example: T0292
    Requirement:
      type: object
      allOf:
        - $ref: '#/components/schemas/BaseRequirement'
        - required:
            - purchase_from
            - purchase_to
          properties:
            purchase_from:
              type: string
              format: date-time
            purchase_to:
              type: string
              format: date-time
    Reward:
      type: object
      required:
        - type
        - value
      properties:
        type:
          type: string
          description: |

            Reward Type:
              * `discount_amount` - value as discount
              * `discount_percent` - value percentage of gross amount
                  as discount
              * `discount_item_new_price` - discount as old price subtracted with value
              * `discount_item_quantity` - number of items to get as discount (free)
              * `discount_item_percent` - percent discount of the cheapest item (stamp)
                  as discount
              * `discount_debit` - value as discount, remaining amount after a
                purchase will be available in future purchases (if not limited by usage)
              * `discount_mix_new_price` - discount as old mix total value (reward_eligible=true)
                subtracted with value
          enum:
            - discount_amount
            - discount_percent
            - discount_item_new_price
            - discount_item_quantity
            - discount_item_percent
            - discount_mix_new_price
            - discount_debit
        value:
          example: 10000
          description: |
            The reward value, unit of the value is resolved
            from the reward type

            Examples:
              - Percent: 10.5
              - Amount: 10000 (amount in smallest unit for the currency)
              - Quantity: 1
          minimum: 0
          oneOf:
            - type: integer
            - type: number
        values:
          description: >
            Reward values that is used to "override" the reward value for
            matching items.

            Add support for having a single rule for multiple items that gives
            different

            reward value for each items


            > Only available for rules where `requirements.item.items` is
            non-empty.
          type: array
          minItems: 1
          items:
            type: object
            required:
              - items
              - value
            properties:
              items:
                type: array
                minItems: 1
                description: >
                  `id` or `group_id` is required, if both are included both id
                  and

                  group id must match
                items:
                  type: object
                  properties:
                    id:
                      type: string
                      example: b714118
                    group_id:
                      type: string
                      example: B1
              value:
                type: number
        base:
          $ref: '#/components/schemas/RewardBase'
        effect:
          type: string
          description: >
            How the reward will be added to the receipt.

            - `discount`: the reward will be applied as a discount directly on
            the receipt

            - `bonus`: the reward will be accumulated as bonus on the customers
            discount balance
          default: discount
          enum:
            - discount
            - bonus
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
          properties:
            code:
              type: string
              description: The code used to identify the error/warning
            errors:
              type: array
              description: The nested error(s) encountered during validation
              items:
                type: object
            message:
              type: string
              description: The human readable description of the error/warning
  responses:
    BadRequest:
      description: Bad / Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    AccessForbidden:
      description: Access forbidden, invalid JWT token was used
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: Forbidden
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Resource was not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ServerError:
      description: Unexpected Error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    JWT:
      type: http
      description: >
        Bearer authentication (token authentication) should be used for
        accessing the API.


        Use [Get
        Token](https://docs.dintero.com/api.html#operation/aid_auths_oauth_token_post)
        to get an access token for client credentials.

        Pass the token in the request header:

            Authorization: Bearer {access_token}

        where the **access_token** is JSON Web Tokens (JWT).
      scheme: bearer
      bearerFormat: JWT

````