{"record":{"id":"a994605054046d01","repo":"medusajs/medusa","slug":"invalid-data-a99460","errorCode":"invalid_data","errorMessage":"Gift card (${input.code}) not found","messagePattern":"Gift card \\((.+?)\\) not found","errorType":"validation","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/plugins/loyalty/src/workflows/carts/workflows/add-gift-card-to-cart.ts","lineNumber":107,"sourceCode":"   */\n  giftCard: ModuleGiftCard\n  /**\n   * The lookup input containing the gift card code.\n   */\n  input: { code: string }\n}\n\n/**\n * Validate if the gift card exists.\n */\nconst validateGiftCardStep = createStep(\n  \"validate-gift-card\",\n  async function ({\n    giftCard,\n    input,\n  }: ValidateGiftCardExistsStepInput) {\n    if (!giftCard) {\n      throw new MedusaError(\n        MedusaError.Types.INVALID_DATA,\n        `Gift card (${input.code}) not found`\n      );\n    }\n  }\n);\n\n/**\n * Input to validate that gift cards can be added to a cart.\n */\nexport interface ValidateCartGiftCardStepInput {\n  /**\n   * The cart to validate against, including its currently applied gift cards.\n   */\n  cart: PluginCartDTO\n  /**\n   * The gift cards to apply to the cart.\n   */","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/plugins/loyalty/src/workflows/carts/workflows/add-gift-card-to-cart.ts#L89-L125","documentation":"The validate-gift-card step in addGiftCardToCartWorkflow throws INVALID_DATA when the gift card looked up by code does not exist. This runs before any cart mutation, so the cart is unchanged.","triggerScenarios":"Calling add-gift-card-to-cart with a typo'd, malformed, or deleted/disabled gift card code; the useQueryGraphStep lookup returned null/undefined.","commonSituations":"User pastes a code with whitespace or wrong casing, the gift card was deactivated in admin, or the code belongs to another region/currency scope not covered by the query filters.","solutions":["Trim and normalize the code before invoking the workflow","Verify the gift card exists (and is active) via listGiftCards before adding","Return a friendly 'invalid code' message to the customer on this error"],"exampleFix":"// before\nawait addGiftCardToCartWorkflow.run({ input: { cart_id, code } })\n// after\nconst code = rawCode.trim()\nconst [gc] = await query.graph({ entity: 'gift_card', filters: { code } })\nif (gc) await addGiftCardToCartWorkflow.run({ input: { cart_id, code } })","handlingStrategy":"validation","validationCode":"const code = rawCode.trim()\nconst [gc] = await query.graph({ entity: 'gift_card', filters: { code } })\nif (!gc) return { error: 'Invalid gift card code' }","typeGuard":null,"tryCatchPattern":"try { await workflow.run(...) } catch (e) { if (/not found/.test(e.message)) return notFoundResponse }","preventionTips":["Trim/normalize codes client-side","Verify the card is active before applying"],"tags":["gift-card","not-found","cart","loyalty"],"backgroundTag":"entity-not-found","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}