medusajs/medusa · error · MedusaError

application_method.apply_to_quantity is a required field for

Error message

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

What it means

For buy-get promotions, application_method.apply_to_quantity is required — this is the later redundant guard reached when earlier presence checks passed via different code paths (e.g., attribute spread/merge on update). It throws INVALID_DATA when the effective applyToQuantity is absent.

Source

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

      )
    }

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

    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(

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Always send the complete buy-get application method on update, including apply_to_quantity
  2. After building the payload, assert all three buy-get fields are defined before calling the module
  3. Refetch the promotion and merge with existing application_method values instead of replacing

Example fix

// before
await promotionModule.updatePromotions({ id, application_method: { max_quantity: 2 } })

// after
const existing = await promotionModule.retrievePromotion(id, { relations: ["application_method"] })
await promotionModule.updatePromotions({
  id,
  application_method: {
    ...existing.application_method,
    max_quantity: 2,
    apply_to_quantity: 1,
    buy_rules_min_quantity: 2,
  },
})
Defensive patterns

Strategy: validation

Validate before calling

const merged = { ...existing.application_method, ...patch }
if (promoType === "buyget" && merged.apply_to_quantity == null) throw new Error("apply_to_quantity missing after merge")

Type guard

const isCompleteBuyGetMethod = (am: Record<string, unknown> | undefined): boolean => !!am && am.apply_to_quantity != null && am.buy_rules_min_quantity != null && am.max_quantity != null

Try / catch

try { await updatePromotions(...) } catch (e) { if (e.type === MedusaError.Types.INVALID_DATA && /apply_to_quantity is a required field/.test(e.message)) { /* merge full application method and retry */ } throw e }

Prevention

When it happens

Trigger: Updating a buyget promotion with a partial application_method payload that carries max_quantity and buy_rules_min_quantity but drops apply_to_quantity (merged object ends up without it), or create payloads where the field is present but undefined.

Common situations: Patch-style updates that rebuild the application method object and lose fields, ORM hydration returning null, double-submit with partially validated data.

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/8401c63d40cd58c9. Report an issue: GitHub.