payloadcms/payload · error · APIError

The collection with slug ${String(collectionSlug)} can't be

Error message

The collection with slug ${String(collectionSlug)} can't be found. Create Operation.

What it means

Thrown by the Local API `create` wrapper in packages/payload/src/collections/operations/local/create.ts:213 when `payload.create({ collection })` targets a slug absent from `payload.collections`. It is a 500 APIError (no status passed) and is raised before `createLocalReq`, so no file handling, hooks, or access control execute.

Source

Thrown at packages/payload/src/collections/operations/local/create.ts:213

    depth,
    disableTransaction,
    disableVerificationEmail,
    draft,
    duplicateFromID,
    file,
    filePath,
    overrideAccess = true,
    overwriteExistingFiles = false,
    populate,
    publishAllLocales,
    select,
    showHiddenFields,
  } = options

  const collection = payload.collections[collectionSlug]

  if (!collection) {
    throw new APIError(
      `The collection with slug ${String(collectionSlug)} can't be found. Create Operation.`,
    )
  }

  const req = await createLocalReq(options as CreateLocalReqOptions, payload)

  req.file = file ?? (await getFileByPath(filePath!))

  return createOperation<TSlug, TSelect>({
    collection,
    data: deepCopyObjectSimple(data), // Ensure mutation of data in create operation hooks doesn't affect the original data
    depth,
    disableTransaction,
    disableVerificationEmail,
    draft,
    duplicateFromID,
    overrideAccess,
    overwriteExistingFiles,

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Match the `collection` argument to the exact `slug` defined in the collection config.
  2. If the slug comes from external input, validate it against `Object.keys(payload.collections)` before calling create.
  3. Make sure `payload.init()` resolved and any plugins that register the collection are loaded.
  4. Remove `as CollectionSlug` casts so TypeScript's literal union rejects unknown slugs.

Example fix

// before
await payload.create({ collection: 'article' as CollectionSlug, data }) // slug is 'articles'

// after
await payload.create({ collection: 'articles', data })
Defensive patterns

Strategy: validation

Validate before calling

function assertCollectionSlug(payload: Payload, slug: string): void {
  if (!(slug in payload.collections)) {
    throw new Error(`Unknown collection slug '${slug}'`)
  }
}
assertCollectionSlug(payload, 'articles')
await payload.create({ collection: 'articles', data })

Type guard

const slugIsRegistered = (payload: Payload, slug: string): slug is CollectionSlug =>
  slug in (payload.collections as Record<string, unknown>)

if (slugIsRegistered(payload, slug)) {
  await payload.create({ collection: slug, data })
}

Try / catch

try {
  await payload.create({ collection: slug, data })
} catch (err) {
  if (err instanceof APIError && /Create Operation/.test(err.message)) {
    // unknown slug — do not retry; correct the slug
  } else throw err
}

Prevention

When it happens

Trigger: Calling `payload.create({ collection: 'user', data })` when the collection slug is `'users'`; seeding data via a script that references a collection removed in the current config; creating through a generic helper that receives a slug from an HTTP body or env var that doesn't match any collection.

Common situations: A `slug` typo; using a slug from a different environment whose Payload config differs; casting an untrusted input string with `as CollectionSlug`; a plugin that conditionally registers a collection was not loaded.

Related errors


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