medusajs/medusa · error · MedusaError
invalid_data
invalid_data
Error message
Gift card does not have a store credit account
What it means
Validation in claim-gift-card workflow's transform: the gift card exists but its store_credit_account is missing or has no id. Claiming converts the gift card's value into a store credit account, so an account must already be linked to the card.
Source
Thrown at packages/plugins/loyalty/src/workflows/gift-cards/workflows/claim-gift-card.ts:57
* },
* customer: {
* has_account: true,
* // other customer properties...
* },
* })
*/
export const validateClaimGiftCardInputStep = createStep(
"validate-claim-gift-card-input",
async function (args: {
giftCard: ModuleGiftCard & {
store_credit_account: { id: string; code: string }
}
customer: CustomerDTO
}) {
const { giftCard, customer } = args
if (!giftCard.store_credit_account?.id) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Gift card does not have a store credit account"
)
}
if (!giftCard.store_credit_account.code) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Gift card does not have a store credit account code"
)
}
if (!customer.has_account) {
throw new MedusaError(
MedusaError.Types.INVALID_DATA,
"Only customers with an account can claim a gift card"
)
}View on GitHub (pinned to 5e06e544a2)
Solutions
- Ensure the gift card query includes store_credit_account.id in fields
- Create/attach a store credit account for the gift card (redeem or the account-creation flow) before claiming
- Upgrade the loyalty plugin so newly created gift cards always get a store credit account
Example fix
// before fields: ["id", "code"] // after fields: ["id", "code", "store_credit_account.id", "store_credit_account.code"]
Defensive patterns
Strategy: validation
Validate before calling
const { data } = await query.graph({ entity: "gift_card", filters: { id }, fields: ["id", "store_credit_account.id", "store_credit_account.code"] })
if (!data[0]?.store_credit_account?.id) throw new Error("Gift card has no store credit account") Type guard
const hasStoreCreditAccount = (gc: any): gc is { store_credit_account: { id: string; code: string } } =>
!!gc?.store_credit_account?.id Prevention
- Always include store_credit_account.* in gift card query fields
- Create accounts at gift card creation time via plugin hooks
When it happens
Trigger: Calling claim-gift-card workflow for a gift card that was created without an associated store credit account, or when the query config forgot to select the store_credit_account relation so it resolves to undefined.
Common situations: Gift cards created via direct module inserts or seed scripts that skip account creation; querying with fields that omit 'store_credit_account.*'; cards created before a plugin version that auto-created accounts.
Related errors
- not_found
- invalid_data
- invalid_data
- Cannot add promotions to campaign where currency_code don't
- "${contextKey}" should be present as an array in the context
AI-assisted analysis of medusajs/medusa@5e06e544a2 (2026-08-27).
Data as JSON: /api/errors/284a409fe3551b5f.
Report an issue: GitHub.