{"record":{"id":"b74e027a9f6ff29e","repo":"medusajs/medusa","slug":"inventory-level-for-item-id-at-location-locat","errorCode":null,"errorMessage":"Inventory Level for Item ${id} at Location ${location_id} not found","messagePattern":"Inventory Level for Item (.+?) at Location (.+?) not found","errorType":"http","errorClass":"MedusaError","httpStatus":404,"severity":"error","filePath":"packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts","lineNumber":29,"sourceCode":"import { HttpTypes } from \"@medusajs/framework/types\"\nimport { refetchInventoryItem } from \"../../../helpers\"\n\nexport const DELETE = async (\n  req: MedusaRequest<{}, HttpTypes.AdminGetInventoryLocationLevelParams>,\n  res: MedusaResponse<HttpTypes.AdminInventoryLevelDeleteResponse>\n) => {\n  const { id, location_id } = req.params\n\n  const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)\n\n  const result = await query.graph({\n    entity: \"inventory_level\",\n    filters: { inventory_item_id: id, location_id },\n    fields: [\"id\", \"reserved_quantity\"],\n  })\n\n  if (!result.data.length) {\n    throw new MedusaError(\n      MedusaError.Types.NOT_FOUND,\n      `Inventory Level for Item ${id} at Location ${location_id} not found`\n    )\n  }\n\n  const { id: levelId, reserved_quantity: reservedQuantity } = result.data[0]\n\n  if (reservedQuantity > 0) {\n    throw new MedusaError(\n      MedusaError.Types.NOT_ALLOWED,\n      `Cannot remove Inventory Level ${id} at Location ${location_id} because there are reservations at location`\n    )\n  }\n\n  const deleteInventoryLevelWorkflow = deleteInventoryLevelsWorkflow(req.scope)\n\n  await deleteInventoryLevelWorkflow.run({\n    input: {","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/medusa/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts#L11-L47","documentation":"The DELETE /admin/inventory-items/:id/location_levels/:location_id route queries for an inventory_level matching both the inventory item id and the location id; no match throws NOT_FOUND (HTTP 404).","triggerScenarios":"DELETE on an inventory item/location pair where no level exists — wrong location id, level already deleted, or item never stocked at that location.","commonSituations":"Double-click/retry of a delete that already succeeded; UI listing stale location levels; using a stock location id from a different store.","solutions":["GET the item's location levels first and delete only listed pairs","Treat 404 on delete as already-deleted and continue idempotently","Refresh the levels list after any delete"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const { inventory_item } = await sdk.inventoryItem.retrieve(itemId, { fields: [\"location_levels.*\"] })\nconst hasLevel = inventory_item.location_levels?.some((l) => l.location_id === locationId)\nif (!hasLevel) throw new Error(`No level for ${itemId} at ${locationId}`)","typeGuard":"const levelExists = (levels: {location_id:string}[], locId: string) =>\n  levels.some((l) => l.location_id === locId)","tryCatchPattern":"try { await deleteLevel(itemId, locationId) } catch (e) { if (e.statusCode === 404) { /* already deleted, success */ return } throw e }","preventionTips":["Refresh level lists after deletes","Treat 404 on delete as success for idempotency"],"tags":["admin-api","inventory","location-levels","not-found"],"backgroundTag":"http-404-nested-resource-not-found","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}