{"record":{"id":"7efb06a601ba80a6","repo":"payloadcms/payload","slug":"the-collection-with-slug-string-collectionslug-7efb06","errorCode":null,"errorMessage":"The collection with slug ${String(collectionSlug)} can't be found. Create Operation.","messagePattern":"The collection with slug (.+?) can't be found\\. Create Operation\\.","errorType":"http","errorClass":"APIError","httpStatus":500,"severity":"error","filePath":"packages/payload/src/collections/operations/local/create.ts","lineNumber":213,"sourceCode":"    depth,\n    disableTransaction,\n    disableVerificationEmail,\n    draft,\n    duplicateFromID,\n    file,\n    filePath,\n    overrideAccess = true,\n    overwriteExistingFiles = false,\n    populate,\n    publishAllLocales,\n    select,\n    showHiddenFields,\n  } = options\n\n  const collection = payload.collections[collectionSlug]\n\n  if (!collection) {\n    throw new APIError(\n      `The collection with slug ${String(collectionSlug)} can't be found. Create Operation.`,\n    )\n  }\n\n  const req = await createLocalReq(options as CreateLocalReqOptions, payload)\n\n  req.file = file ?? (await getFileByPath(filePath!))\n\n  return createOperation<TSlug, TSelect>({\n    collection,\n    data: deepCopyObjectSimple(data), // Ensure mutation of data in create operation hooks doesn't affect the original data\n    depth,\n    disableTransaction,\n    disableVerificationEmail,\n    draft,\n    duplicateFromID,\n    overrideAccess,\n    overwriteExistingFiles,","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/collections/operations/local/create.ts#L195-L231","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Match the `collection` argument to the exact `slug` defined in the collection config.","If the slug comes from external input, validate it against `Object.keys(payload.collections)` before calling create.","Make sure `payload.init()` resolved and any plugins that register the collection are loaded.","Remove `as CollectionSlug` casts so TypeScript's literal union rejects unknown slugs."],"exampleFix":"// before\nawait payload.create({ collection: 'article' as CollectionSlug, data }) // slug is 'articles'\n\n// after\nawait payload.create({ collection: 'articles', data })","handlingStrategy":"validation","validationCode":"function assertCollectionSlug(payload: Payload, slug: string): void {\n  if (!(slug in payload.collections)) {\n    throw new Error(`Unknown collection slug '${slug}'`)\n  }\n}\nassertCollectionSlug(payload, 'articles')\nawait payload.create({ collection: 'articles', data })","typeGuard":"const slugIsRegistered = (payload: Payload, slug: string): slug is CollectionSlug =>\n  slug in (payload.collections as Record<string, unknown>)\n\nif (slugIsRegistered(payload, slug)) {\n  await payload.create({ collection: slug, data })\n}","tryCatchPattern":"try {\n  await payload.create({ collection: slug, data })\n} catch (err) {\n  if (err instanceof APIError && /Create Operation/.test(err.message)) {\n    // unknown slug — do not retry; correct the slug\n  } else throw err\n}","preventionTips":["When the slug comes from HTTP input, allowlist it against payload.collections.","Await payload.init() in scripts before creating.","Never cast untrusted strings to CollectionSlug."],"tags":["local-api","collection","slug","create","configuration"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}