{"record":{"id":"6e481a326ada4ae2","repo":"medusajs/medusa","slug":"buy-rules-min-quantity-is-a-required-field-for-pro","errorCode":null,"errorMessage":"buy_rules_min_quantity is a required field for Promotion type of ${PromotionType.BUYGET}","messagePattern":"buy_rules_min_quantity is a required field for Promotion type of (.+?)","errorType":"validation","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/modules/promotion/src/utils/validations/application-method.ts","lineNumber":68,"sourceCode":"    type === ApplicationMethodType.PERCENTAGE &&\n    (MathBN.lte(value, 0) || MathBN.gt(value, 100))\n  ) {\n    throw new MedusaError(\n      MedusaError.Types.INVALID_DATA,\n      `Application Method value should be a percentage number between 0 and 100`\n    )\n  }\n\n  if (promotion?.type === PromotionType.BUYGET) {\n    if (!isPresent(applyToQuantity)) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `apply_to_quantity is a required field for Promotion type of ${PromotionType.BUYGET}`\n      )\n    }\n\n    if (!isPresent(buyRulesMinQuantity)) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `buy_rules_min_quantity is a required field for Promotion type of ${PromotionType.BUYGET}`\n      )\n    }\n\n    if (!isPresent(maxQuantity)) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `application_method.max_quantity is a required field for Promotion type of ${PromotionType.BUYGET}`\n      )\n    }\n\n    if (!isPresent(applyToQuantity)) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `application_method.apply_to_quantity is a required field for Promotion type of ${PromotionType.BUYGET}`\n      )\n    }","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/modules/promotion/src/utils/validations/application-method.ts#L50-L86","documentation":"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_.","triggerScenarios":"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.","commonSituations":"Forms omitting the 'minimum buy quantity' input, API integrations built against older payloads that lacked the field, seed scripts with partial application methods.","solutions":["Set buy_rules_min_quantity (e.g., 2 for buy-2-get-1) in the application method","Collect the field in the creation form whenever promotion type is buyget","Validate the whole buy-get field set (apply_to_quantity, buy_rules_min_quantity, max_quantity) together before submitting"],"exampleFix":"// before\napplication_method: { type: \"percentage\", value: 100, target_type: \"items\", apply_to_quantity: 1 }\n\n// after\napplication_method: { type: \"percentage\", value: 100, target_type: \"items\", apply_to_quantity: 1, buy_rules_min_quantity: 2, max_quantity: 1 }","handlingStrategy":"validation","validationCode":"if (type === \"buyget\" && !isPresent(applicationMethod.buy_rules_min_quantity)) {\n  throw new Error(\"buy_rules_min_quantity required for buyget\")\n}","typeGuard":"const hasBuyRulesMinQuantity = (am: { buy_rules_min_quantity?: number | null }): boolean => am.buy_rules_min_quantity != null","tryCatchPattern":"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 }","preventionTips":["Collect minimum buy quantity in the buy-get form","Never null out buy-get fields on updates","Bundle-verify all buy-get fields pre-submit"],"tags":["promotion","buy-get","validation","required-field","medusa"],"backgroundTag":"missing-required-field","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}