medusajs/medusa · error · MedusaError

buy_rules_min_quantity is a required field for Promotion typ

Error message

buy_rules_min_quantity is a required field for Promotion type of ${PromotionType.BUYGET}

What it means

For buy-get promotions, application_method.buy_rules_min_quantity (minimum quantity to buy to qualify) is required. Missing/null triggers INVALID_DATA during createPromotions_ or updatePromotions_.

Source

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

    type === ApplicationMethodType.PERCENTAGE &&
    (MathBN.lte(value, 0) || MathBN.gt(value, 100))
  ) {
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      `Application Method value should be a percentage number between 0 and 100`
    )
  }

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

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

    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}`
      )
    }

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Set buy_rules_min_quantity (e.g., 2 for buy-2-get-1) in the application method
  2. Collect the field in the creation form whenever promotion type is buyget
  3. Validate the whole buy-get field set (apply_to_quantity, buy_rules_min_quantity, max_quantity) together before submitting

Example fix

// before
application_method: { type: "percentage", value: 100, target_type: "items", apply_to_quantity: 1 }

// after
application_method: { type: "percentage", value: 100, target_type: "items", apply_to_quantity: 1, buy_rules_min_quantity: 2, max_quantity: 1 }
Defensive patterns

Strategy: validation

Validate before calling

if (type === "buyget" && !isPresent(applicationMethod.buy_rules_min_quantity)) {
  throw new Error("buy_rules_min_quantity required for buyget")
}

Type guard

const hasBuyRulesMinQuantity = (am: { buy_rules_min_quantity?: number | null }): boolean => am.buy_rules_min_quantity != null

Try / catch

try { await createPromotions(...) } catch (e) { if (e.type === MedusaError.Types.INVALID_DATA && /buy_rules_min_quantity/.test(e.message)) { /* set buy_rules_min_quantity and resubmit */ } throw e }

Prevention

When it happens

Trigger: Creating a buyget promotion without buy_rules_min_quantity in the application_method, or an update payload that sets it to null/undefined while retaining type buyget.

Common situations: Forms omitting the 'minimum buy quantity' input, API integrations built against older payloads that lacked the field, seed scripts with partial application methods.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


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