medusajs/medusa · error · MedusaError

Invalid param rule_type (${ruleType})

Error message

Invalid param rule_type (${ruleType})

What it means

Thrown by validateRuleType when the rule_type param, after converting dashes to underscores, is not one of the RuleType enum values. It guards promotion rule endpoints that branch behavior on the rule type.

Source

Thrown at packages/medusa/src/api/admin/promotions/utils/validate-rule-type.ts:9

import { MedusaError, RuleType } from "@medusajs/framework/utils"

const validRuleTypes: string[] = Object.values(RuleType)

export function validateRuleType(ruleType: string) {
  const underscorizedRuleType = ruleType.split("-").join("_")

  if (!validRuleTypes.includes(underscorizedRuleType)) {
    throw new MedusaError(
      MedusaError.Types.INVALID_DATA,
      `Invalid param rule_type (${ruleType})`
    )
  }
}

View on GitHub (pinned to 5e06e544a2)

Solutions

  1. Check the RuleType enum values in @medusajs/framework/utils (or the API docs) and send a valid one
  2. Normalize params client-side: lowercase and hyphenate before sending
  3. Validate the param in your UI before issuing the request

Example fix

// before
GET /admin/promotions/rule-attributes?rule_type=Rule

// after
GET /admin/promotions/rule-attributes?rule_type=rules // use exact enum value, dashes or underscores accepted
Defensive patterns

Strategy: validation

Validate before calling

const VALID = Object.values(RuleType) // e.g. ["rules","rules-v2",...]
const normalized = ruleType.replace(/-/g, "_")
if (!VALID.includes(normalized)) {
  throw new Error(`rule_type must be one of: ${VALID.join(", ")}`)
}

Type guard

const isValidRuleType = (t: string) =>
  Object.values(RuleType).includes(t.replace(/-/g, "_"))

Try / catch

try {
  await fetchRuleAttributes(ruleType)
} catch (e: any) {
  if (e.statusCode === 400 && /rule_type/.test(e.message)) correctParam()
  else throw e
}

Prevention

When it happens

Trigger: Passing rule_type=foo, rule_type=bogus, or an unsupported variant (e.g. 'rules-v2') to a promotion rules endpoint that accepts rule_type as a query param.

Common situations: Typos in query params, custom UIs sending camelCase instead of snake_case ('ruleType'), or code written against an older/newer RuleType enum that changed values.

Related errors


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