payloadcms/payload · warning · APIError

Missing ID of version.

Error message

Missing ID of version.

What it means

In `findVersionByIDOperation`, if `id` is falsy it throws `APIError` (400). A version ID is required to look up a specific version.

Source

Thrown at packages/payload/src/collections/operations/findVersionByID.ts:52

  args: Arguments,
): Promise<TypeWithVersion<TData>> => {
  const {
    id,
    collection: { config: collectionConfig },
    currentDepth,
    depth,
    disableErrors,
    overrideAccess,
    populate,
    req: { fallbackLocale, locale, payload },
    req,
    select: incomingSelect,
    showHiddenFields,
    trash = false,
  } = args

  if (!id) {
    throw new APIError('Missing ID of version.', httpStatus.BAD_REQUEST)
  }

  try {
    // /////////////////////////////////////
    // beforeOperation - Collection
    // /////////////////////////////////////

    args = await buildBeforeOperation({
      args,
      collection: collectionConfig,
      operation: 'findVersionByID',
      overrideAccess,
    })

    // /////////////////////////////////////
    // Access
    // /////////////////////////////////////

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Pass a non-empty version `id`.
  2. Validate the param before the call.

Example fix

// before
await payload.findVersionByID({ collection: 'posts', id: maybeId })
// after
if (!id) throw new Error('version id required')
await payload.findVersionByID({ collection: 'posts', id })
Defensive patterns

Strategy: validation

Validate before calling

function requireVersionId(id) {
  if (!id) throw new Error('version id required')
}

Type guard

function hasVersionId(id): id is string | number {
  return id !== undefined && id !== null && id !== ''
}

Prevention

When it happens

Trigger: `findVersionByID({ collection, id })` (or `GET /api/{collection}/versions/{id}`) with no id, or `id: undefined`.

Common situations: Route param missing; id variable undefined; a refactor dropped the id argument.

Related errors


AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12). Data as JSON: /api/errors/cffa2351d3167eeb. Report an issue: GitHub.