medusajs/medusa · error · MedusaError
apply_to_quantity is a required field for Promotion type of
Error message
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 (how many items the customer gets discounted) must be present. The BUYGET branch of validateApplicationMethodAttributes throws INVALID_DATA when it is missing.
Source
Thrown at packages/modules/promotion/src/utils/validations/application-method.ts:61
const applicationMethodType = data.type || applicationMethod?.type
const value = new BigNumber(data.value ?? applicationMethod.value ?? 0)
const maxQuantity = data.max_quantity || applicationMethod.max_quantity
const allocation = data.allocation || applicationMethod.allocation
const allTargetTypes: string[] = Object.values(ApplicationMethodTargetType)
if (
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}`
)
}View on GitHub (pinned to 5e06e544a2)
Solutions
- Add apply_to_quantity to the application_method payload (e.g., 1 for buy-1-get-1)
- Ensure the admin/custom form collects apply_to_quantity when promotion type is buyget
- Never send null for the field on updates; send the full buy-get field set
Example fix
// before
await promotionModule.createPromotions({ code: "B2G1", type: "buyget", application_method: { type: "percentage", value: 100, target_type: "items", buy_rules_min_quantity: 2 } })
// after
await promotionModule.createPromotions({ code: "B2G1", type: "buyget", 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 (promo.type === "buyget") {
const required = ["apply_to_quantity", "buy_rules_min_quantity", "max_quantity"]
const missing = required.filter((k) => !isPresent(promo.application_method?.[k]))
if (missing.length) throw new Error(`missing: ${missing.join(", ")}`)
} Type guard
const isCompleteBuyGetMethod = (am: Record<string, unknown> | undefined): boolean => !!am && ["apply_to_quantity", "buy_rules_min_quantity", "max_quantity"].every((k) => am[k] != null)
Try / catch
try { await createPromotions(...) } catch (e) { if (e.type === MedusaError.Types.INVALID_DATA && /apply_to_quantity is a required field/.test(e.message)) { /* add the field and resubmit */ } throw e } Prevention
- Use one shared buy-get payload template with all required fields
- Show all buy-get fields when type is buyget in the UI
- Validate the full field set before submit
When it happens
Trigger: Creating a promotion with type 'buyget' whose application_method omits apply_to_quantity, or an update that clears it.
Common situations: Copy-pasting a standard promotion payload for a buy-get promo and forgetting the buy-get-only fields, admin form not rendering buy-get fields conditionally, partial updates that unset the field with null.
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
- buy_rules_min_quantity is a required field for Promotion typ
- application_method.max_quantity is a required field for Prom
- application_method.apply_to_quantity is a required field for
- max_quantity (${maxQuantity}) must be greater than or equal
- Cannot add promotions to campaign where currency_code don't
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/d814ad9af25f8090.
Report an issue: GitHub.