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

# Create Stacking Rules

> Overwrites the default stacking rules.

If new stacking rules have been created for the project earlier (e.g. in the user interface), it returns an error. Use [Update stacking rules](/api-reference/management/update-stacking-rules) endpoint to change the rules.

> 📘 Stacking rules documentation
>
> Read [the Stacking rules article]/orchestrate/stacking-rules to learn how they work.



## OpenAPI

````yaml /openapi/management.json post /management/v1/projects/{projectId}/stacking-rules
openapi: 3.0.1
info:
  title: Voucherify API - Management
  version: v2018-08-01
  description: >-
    Voucherify promotion engine REST API. Please see
    https://docs.voucherify.io/docs for more details.
  contact:
    name: Voucherify Team
    url: https://www.voucherify.io/contact-support
    email: support@voucherify.io
  termsOfService: https://www.voucherify.io/legal/subscription-agreement
  license:
    name: MIT
    url: https://github.com/voucherifyio/voucherify-js-sdk/blob/main/LICENSE
servers:
  - url: https://{cluster}.voucherify.io
    description: Base URL
    variables:
      cluster:
        default: api
        enum:
          - api
          - us1.api
          - as1.api
          - download
          - us1.download
          - as1.download
security: []
paths:
  /management/v1/projects/{projectId}/stacking-rules:
    parameters:
      - schema:
          $ref: '#/components/schemas/ParameterProjectId'
        in: path
        name: projectId
        description: Provide the unique identifier of the project.
        required: true
    post:
      tags:
        - Management
      summary: Create Stacking Rules
      description: >-
        Overwrites the default stacking rules.


        If new stacking rules have been created for the project earlier (e.g. in
        the user interface), it returns an error. Use [Update stacking
        rules](/api-reference/management/update-stacking-rules) endpoint to
        change the rules.


        > 📘 Stacking rules documentation

        >

        > Read [the Stacking rules article]/orchestrate/stacking-rules to learn
        how they work.
      operationId: create-stacking-rules
      parameters: []
      requestBody:
        description: Defines the stacking rule parameters.
        content:
          application/json:
            schema:
              $ref: >-
                #/components/schemas/ManagementProjectsStackingRulesCreateRequestBody
        required: true
      responses:
        '200':
          description: >-
            Returns the details about the stacking rules assigned to the
            project.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/ManagementProjectsStackingRulesCreateResponseBody
              examples:
                Example:
                  value:
                    id: stk_0e9bdfd48108548fd3
                    exclusive_categories:
                      - cat_0f2ba1284b565c235c
                      - cat_0d75bdfe4c9030a732
                    joint_categories:
                      - cat_0d74559c3e9030da13
                      - cat_0d507a4d6e8a1b7b97
                    redeemables_limit: 25
                    applicable_redeemables_limit: 10
                    applicable_redeemables_per_category_limit: 2
                    applicable_redeemables_category_limits:
                      cat_0d75bdfe4c9030a732: 1
                      cat_0d7c4d183011d043cc: 2
                    applicable_exclusive_redeemables_limit: 2
                    applicable_exclusive_redeemables_per_category_limit: 2
                    discount_calculation_mode: DISCOUNTED_AMOUNT
                    initial_amount_mode_categories:
                      - cat_0d507a4d6e8a1b7b97
                    discounted_amount_mode_categories:
                      - cat_0d7455f93c1030da4a
                    redeemables_application_mode: PARTIAL
                    redeemables_sorting_rule: CATEGORY_HIERARCHY
                    redeemables_no_effect_rule: REDEEM_ANYWAY
                    no_effect_skip_categories: []
                    no_effect_redeem_anyway_categories: []
                    redeemables_products_application_mode: ONCE
                    redeemables_rollback_order_mode: WITH_ORDER
                    grouped_redeemables_sorting_rule: JOINT_ALWAYS_LAST
                    created_at: '2024-04-16T20:18:38.213Z'
        '400':
          description: >-
            Returns an error if the payload has incorrect values, e.g. integer
            limits.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/e_400_invalid_payload'
              examples:
                Invalid payload:
                  value:
                    code: 400
                    key: invalid_payload
                    message: Invalid payload
                    details: >-
                      Property .applicable_exclusive_redeemables_limit must be
                      <= 30
                    request_id: v-0e9b7334154228a45f
        '401':
          description: Returns an error if an invalid token was provided.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Unauthorized:
                  value:
                    code: 401
                    message: Unauthorized
                    key: unauthorized
        '402':
          description: >-
            Returns an error if the current plan does not include the Management
            API feature.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorPaymentRequired'
              examples:
                Example:
                  value:
                    code: 402
                    message: Payment required
                    details: >-
                      Your current plan does not include a feature required to
                      perform this operation.
                    key: missing_required_feature
        '404':
          description: Returns an error when a resource could not be found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Resource not found:
                  value:
                    code: 404
                    key: not_found
                    message: Resource not found
                    details: Cannot find customer with id cust_xqA7DGj5eYPHg6PHVKwYRWiA
                    request_id: v-0c8b6b35294af6f192
                    resource_id: cust_xqA7DGj5eYPHg6PHVKwYRWiA
                    resource_type: customer
        '409':
          description: >-
            Returns an error if the stacking rules have been already created for
            the project.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                Example:
                  value:
                    code: 409
                    key: stacking_rules_exist
                    message: Stacking rules exist
                    details: Cannot exist more stacking rules for given project
                    request_id: v-0e9b5f39f550e070c4
      security:
        - X-Management-Id: []
          X-Management-Token: []
components:
  schemas:
    ParameterProjectId:
      type: string
      example: proj_TrlkLiH4
    ManagementProjectsStackingRulesCreateRequestBody:
      type: object
      description: >-
        Request body schema for **POST**
        `/management/v1/projects/{projectId}/stacking-rules`.
      allOf:
        - $ref: '#/components/schemas/ManagementProjectsStackingRulesBase'
    ManagementProjectsStackingRulesCreateResponseBody:
      type: object
      description: >-
        Response body schema for **POST**
        `/management/v1/projects/{projectId}/stacking-rules`.
      allOf:
        - $ref: '#/components/schemas/ManagementProjectsStackingRules'
      required:
        - id
        - created_at
    e_400_invalid_payload:
      title: Invalid Payload
      type: object
      description: 'Error: Bad Request &rarr; Invalid Payload'
      properties:
        code:
          type: integer
          default: 400
          description: Error's HTTP status code.
        key:
          type: string
          default: invalid_payload
          description: Short string describing the kind of error which occurred.
        message:
          type: string
          default: Invalid payload
          description: A human-readable message providing a short description of the error.
        details:
          type: string
          description: A human-readable message providing more details about the error.
        request_id:
          type: string
          example: v-0a884c6be8c3756f42
          description: >-
            This ID is useful when troubleshooting and/or finding the root cause
            of an error response by our support team.
    Error:
      title: Error Object
      type: object
      description: Error details
      properties:
        code:
          type: integer
          description: Error's HTTP status code.
        key:
          type: string
          description: Short string describing the kind of error which occurred.
        message:
          type: string
          description: A human-readable message providing a short description of the error.
        details:
          type: string
          description: A human-readable message providing more details about the error.
        request_id:
          type: string
          example: v-0a885062c80375740f
          description: >-
            This ID is useful when troubleshooting and/or finding the root cause
            of an error response by our support team.
        resource_id:
          type: string
          description: >-
            Unique resource ID that can be used in another endpoint to get more
            details.
          example: rf_0c5d710a87c8a31f86
        resource_type:
          type: string
          description: The resource type.
          example: voucher
        error:
          type: object
          description: Includes additional information about the error.
          properties:
            message:
              type: string
              description: The message configured by the user in a validation rule.
      required:
        - code
        - message
    ErrorPaymentRequired:
      title: Payment Required Error
      type: object
      description: 'Error: Payment required - the current plan does not include the feature.'
      properties:
        code:
          type: integer
          description: Error's HTTP status code.
        message:
          type: string
          description: A human-readable message providing a short description of the error.
        details:
          type: string
          description: A human-readable message providing more details about the error.
        key:
          type: string
          description: Short string describing the kind of error which occurred.
      required:
        - code
        - message
        - details
        - key
    ManagementProjectsStackingRulesBase:
      type: object
      description: Object representing basic stacking rule parameters.
      properties:
        exclusive_categories:
          type: array
          description: >-
            Lists the IDs of exclusive categories. A redeemable from a campaign
            with an exclusive category is the only redeemable to be redeemed
            when applied with redeemables from other campaigns unless these
            campaigns are exclusive or joint.
          items:
            type: string
        joint_categories:
          type: array
          description: >-
            Lists the IDs of the joint categories. A campaign with a joint
            category is always applied regardless of the exclusivity of other
            campaigns.
          items:
            type: string
        redeemables_limit:
          type: integer
          description: >-
            Defines how many redeemables can be sent in one request. Note: more
            redeemables means more processing time.
          minimum: 1
          maximum: 30
        applicable_redeemables_limit:
          type: integer
          description: >-
            Defines how many redeemables can be applied in one request. The
            number must be less than or equal to `redeemables_limit`. For
            example, a user can select 30 discounts but only 5 will be applied
            to the order and the remaining will be `SKIPPED` according to the
            `redeemables_sorting_rule`.
          minimum: 1
          maximum: 30
        applicable_redeemables_per_category_limit:
          type: integer
          nullable: true
          description: >-
            Defines how many redeemables with the same category can be applied
            in one request. The number must be less than or equal to
            `applicable_redeemables_limit`. The ones above the limit will be
            `SKIPPED` according to the `redeemables_sorting_rule`.
          minimum: 1
          maximum: 30
        applicable_redeemables_category_limits:
          type: object
          description: >-
            Lists categories by category IDs (keys) and defines their limits
            (values) of applicable redeemables that belong to campaigns with
            that category.
          additionalProperties:
            type: integer
            description: Limit of applicable redeemables per category.
            minimum: 1
            maximum: 10
        applicable_exclusive_redeemables_limit:
          type: integer
          description: >-
            Defines how many redeemables with an assigned exclusive category can
            be applied in one request. The ones above the limit will be
            `SKIPPED` according to the `redeemables_sorting_rule`.
          minimum: 1
          maximum: 5
        applicable_exclusive_redeemables_per_category_limit:
          type: integer
          nullable: true
          description: >-
            Defines how many redeemables with an assigned exclusive category can
            be applied in one request. The ones above the limit will be
            `SKIPPED` according to the `redeemables_sorting_rule`. The number
            must be less than or equal to
            `applicable_exclusive_redeemables_limit`.
          minimum: 1
          maximum: 30
        discount_calculation_mode:
          type: string
          description: >-
            Defines if the discounts are applied by taking into account the
            initial order amount or the discounted order amount.
          enum:
            - INITIAL_AMOUNT
            - DISCOUNTED_AMOUNT
        initial_amount_mode_categories:
          type: array
          description: >-
            Lists the IDs of the categories that apply a discount based on the
            initial amount.
          items:
            type: string
        discounted_amount_mode_categories:
          type: array
          description: >-
            Lists the IDs of the categories that apply a discount based on the
            discounted amount.
          items:
            type: string
        redeemables_application_mode:
          type: string
          description: >-
            Defines the application mode for redeemables.

            `"ALL"` means that all redeemables must be validated for the
            redemption to be successful.

            `"PARTIAL"` means that only those redeemables that can be validated
            will be redeemed. The redeemables that fail validaton will be
            skipped.
          enum:
            - ALL
            - PARTIAL
        redeemables_sorting_rule:
          type: string
          description: >-
            Defines redeemables sorting rule. `CATEGORY_HIERARCHY` means that
            redeemables are applied oaccording to the category priority.
            `REQUESTED_ORDER` means that redeemables are applied in the sequence
            provided in the request.
          enum:
            - CATEGORY_HIERARCHY
            - REQUESTED_ORDER
        redeemables_products_application_mode:
          type: string
          description: >-
            Defines redeemables products application mode. `STACK` means that
            multiple discounts can be applied to a product. `ONCE` means that
            only one discount can be applied to the same product.
          enum:
            - STACK
            - ONCE
        redeemables_no_effect_rule:
          type: string
          description: >-
            Defines redeemables no effect rule. `REDEEM_ANYWAY` means that the
            redeemable will be redeemed regardless of any restrictions or
            conditions in place. `SKIP` means that the redeemable will be
            processed only when an applicable effect is calculated.
          enum:
            - REDEEM_ANYWAY
            - SKIP
        no_effect_skip_categories:
          type: array
          description: >-
            Lists category IDs. Redeemables with a given category are skipped
            even if the `redeemables_no_effect_rule` is set to `REDEEM_ANYWAY`.
            Category IDs can't overlap with the IDs in
            `no_effect_redeem_anyway_categories`.
          items:
            type: string
        no_effect_redeem_anyway_categories:
          type: array
          description: >-
            Lists category IDs. Redeemables with a given category are redeemed
            anyway even if the `redeemables_no_effect_rule` is set to `SKIP`.
            Category IDs can't overlap with the IDs in
            `no_effect_skip_categories`.
          items:
            type: string
        redeemables_rollback_order_mode:
          type: string
          description: >-
            Defines the rollback mode for the order. `WITH_ORDER` is a default
            setting. The redemption is rolled back together with the data about
            the order, including related discount values. `WITHOUT_ORDER` allows
            rolling the redemption back without affecting order data, including
            the applied discount values.
          enum:
            - WITH_ORDER
            - WITHOUT_ORDER
    ManagementProjectsStackingRules:
      type: object
      description: Object representing the details of the stacking rules.
      allOf:
        - type: object
          properties:
            id:
              type: string
              description: The unique identifier of the stacking rules.
        - $ref: '#/components/schemas/ManagementProjectsStackingRulesBase'
        - type: object
          properties:
            created_at:
              type: string
              description: >-
                Timestamp representing the date and time when the stacking rules
                were created. The value for this parameter is shown in the ISO
                8601 format.
              format: date-time
              example: '2024-01-02T08:31:46.562Z'
            updated_at:
              type: string
              description: >-
                Timestamp representing the date and time when the stacking rules
                were updated. The value for this parameter is shown in the ISO
                8601 format.
              format: date-time
      required:
        - exclusive_categories
        - joint_categories
        - redeemables_limit
        - applicable_redeemables_limit
        - applicable_redeemables_per_category_limit
        - applicable_redeemables_category_limits
        - applicable_exclusive_redeemables_limit
        - applicable_exclusive_redeemables_per_category_limit
        - discount_calculation_mode
        - initial_amount_mode_categories
        - discounted_amount_mode_categories
        - redeemables_application_mode
        - redeemables_sorting_rule
        - redeemables_products_application_mode
        - redeemables_no_effect_rule
        - no_effect_skip_categories
        - no_effect_redeem_anyway_categories
        - redeemables_rollback_order_mode
  securitySchemes:
    X-Management-Id:
      type: apiKey
      name: X-Management-Id
      in: header
    X-Management-Token:
      type: apiKey
      name: X-Management-Token
      in: header

````