medusajs/medusa · error · MedusaError

max_quantity (${maxQuantity}) must be greater than or equal

Error message

max_quantity (${maxQuantity}) must be greater than or equal to apply_to_quantity (${applyToQuantity}) for BUYGET promotions.

What it means

For buy-get promotions, max_quantity must be >= apply_to_quantity. You cannot cap the number of discounted items below the number of items the promotion says it discounts; violation throws INVALID_DATA.

Source

Thrown at packages/modules/promotion/src/utils/validations/application-method.ts:89

      )
    }

    if (!isPresent(maxQuantity)) {
      throw new MedusaError(
        MedusaError.Types.INVALID_DATA,
        `application_method.max_quantity is a required field for Promotion type of ${PromotionType.BUYGET}`
      )
    }

    if (!isPresent(applyToQuantity)) {
      throw new MedusaError(
        MedusaError.Types.INVALID_DATA,
        `application_method.apply_to_quantity is a required field for Promotion type of ${PromotionType.BUYGET}`
      )
    }

    if (MathBN.lt(maxQuantity!, applyToQuantity!)) {
      throw new MedusaError(
        MedusaError.Types.INVALID_DATA,
        `max_quantity (${maxQuantity}) must be greater than or equal to apply_to_quantity (${applyToQuantity}) for BUYGET promotions.`
      )
    }
  }

  if (
    allocation === ApplicationMethodAllocation.ACROSS &&
    isPresent(maxQuantity)
  ) {
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      `application_method.max_quantity is not allowed to be set for allocation (${ApplicationMethodAllocation.ACROSS})`
    )
  }

  if (!allTargetTypes.includes(targetType)) {
    throw new MedusaError(

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Set max_quantity equal to or greater than apply_to_quantity (a common correct pair is apply_to_quantity=1, max_quantity=1)
  2. Validate the invariant in the form before submission
  3. Fix the data and resubmit the create/update

Example fix

// before
application_method: { apply_to_quantity: 2, buy_rules_min_quantity: 1, max_quantity: 1 }

// after
application_method: { apply_to_quantity: 2, buy_rules_min_quantity: 1, max_quantity: 2 }
Defensive patterns

Strategy: validation

Validate before calling

if (MathBN.lt(maxQuantity, applyToQuantity)) {
  maxQuantity = applyToQuantity // or reject with a clear form error
}

Type guard

const quantitiesConsistent = (am: { max_quantity?: number; apply_to_quantity?: number }): boolean => am.max_quantity == null || am.apply_to_quantity == null || am.max_quantity >= am.apply_to_quantity

Try / catch

try { await createPromotions(...) } catch (e) { if (e.type === MedusaError.Types.INVALID_DATA && /must be greater than or equal to/.test(e.message)) { /* set max_quantity = apply_to_quantity and resubmit */ } throw e }

Prevention

When it happens

Trigger: Creating/updating a buyget promotion with e.g. apply_to_quantity: 3 and max_quantity: 1 (or max_quantity: 0).

Common situations: Misunderstanding the semantics (thinking max_quantity limits the buy side), form defaults setting max_quantity to 1 while apply_to_quantity is higher, data entry errors.

Related errors


AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27). Data as JSON: /api/errors/7724eb046bde5c01. Report an issue: GitHub.