{"record":{"id":"6244e9e8961cc50e","repo":"payloadcms/payload","slug":"missing-id-of-version-to-restore","errorCode":null,"errorMessage":"Missing ID of version to restore.","messagePattern":"Missing ID of version to restore\\.","errorType":"http","errorClass":"APIError","httpStatus":400,"severity":"error","filePath":"packages/payload/src/collections/operations/restoreVersion.ts","lineNumber":75,"sourceCode":"    showHiddenFields,\n  } = args\n\n  try {\n    const shouldCommit = !args.disableTransaction && (await initTransaction(args.req))\n\n    // /////////////////////////////////////\n    // beforeOperation - Collection\n    // /////////////////////////////////////\n\n    args = await buildBeforeOperation({\n      args,\n      collection: args.collection.config,\n      operation: 'restoreVersion',\n      overrideAccess,\n    })\n\n    if (!id) {\n      throw new APIError('Missing ID of version to restore.', httpStatus.BAD_REQUEST)\n    }\n\n    // /////////////////////////////////////\n    // Retrieve original raw version\n    // /////////////////////////////////////\n\n    const { docs: versionDocs } = await req.payload.db.findVersions({\n      collection: collectionConfig.slug,\n      limit: 1,\n      locale: 'all',\n      pagination: false,\n      req,\n      where: { id: { equals: id } },\n    })\n\n    const [rawVersionToRestore] = versionDocs\n\n    if (!rawVersionToRestore) {","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/collections/operations/restoreVersion.ts#L57-L93","documentation":"Thrown at packages/payload/src/collections/operations/restoreVersion.ts:75 with HTTP 400 (BAD_REQUEST) inside `restoreVersionOperation` when the `id` argument is falsy (undefined, null, empty string, 0). It fires after `beforeOperation` hooks but before any database lookup, so an empty id never reaches the versions query.","triggerScenarios":"Calling `payload.restoreVersion({ collection, id: undefined })` or `id: ''`; reading the id from a URL param that is missing and passing it through without validation; destructuring `id` from a request body where the field is absent.","commonSituations":"Route handler does not validate the `:id` path parameter; a UI 'Restore' button submits without a selected version; refactoring that renames the field and leaves `id` undefined.","solutions":["Ensure a non-empty version id is passed to `payload.restoreVersion`.","Validate the incoming id at the API boundary (typeof string/number, non-empty) before calling the Local API.","If the id is optional in your flow, branch before calling restoreVersion rather than passing undefined."],"exampleFix":"// before\nawait payload.restoreVersion({ collection: 'pages', id: req.body.versionId }) // versionId undefined\n\n// after\nconst versionId = req.body.versionId\nif (!versionId) {\n  return res.status(400).json({ error: 'versionId is required' })\n}\nawait payload.restoreVersion({ collection: 'pages', id: versionId })","handlingStrategy":"validation","validationCode":"function assertVersionId(id: unknown): asserts id is string | number {\n  if (id === undefined || id === null || id === '' || id === 0) {\n    throw new Error('A non-empty version id is required for restoreVersion.')\n  }\n}\n\nassertVersionId(versionId)\nawait payload.restoreVersion({ collection: 'pages', id: versionId })","typeGuard":"const hasVersionId = (id: unknown): id is string | number =>\n  (typeof id === 'string' && id.length > 0) || (typeof id === 'number' && id > 0)\n\nif (hasVersionId(versionId)) {\n  await payload.restoreVersion({ collection: 'pages', id: versionId })\n} else {\n  // reject the request at the boundary\n}","tryCatchPattern":"try {\n  await payload.restoreVersion({ collection: 'pages', id: versionId })\n} catch (err) {\n  if (err instanceof APIError && err.status === 400 && /Missing ID of version/.test(err.message)) {\n    // caller omitted the id — return a 400 to the client\n  } else throw err\n}","preventionTips":["Validate path/body params for a non-empty id at the API boundary before calling the Local API.","Disable the Restore UI action until a version is selected.","Type the id as `string | number` and forbid `undefined` in your handler signature."],"tags":["local-api","restore-version","validation","bad-request"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}