{"record":{"id":"dd6948aedc8f68a0","repo":"payloadcms/payload","slug":"collection-with-the-slug-collectionslug-was-not-dd6948","errorCode":null,"errorMessage":"Collection with the slug ${collectionSlug} was not found","messagePattern":"Collection with the slug (.+?) was not found","errorType":"exception","errorClass":"APIError","httpStatus":404,"severity":"error","filePath":"packages/payload/src/utilities/getRequestEntity.ts","lineNumber":17,"sourceCode":"import type { Collection } from '../collections/config/types.js'\nimport type { SanitizedGlobalConfig } from '../globals/config/types.js'\nimport type { PayloadRequest } from '../types/index.js'\n\nimport { APIError } from '../errors/APIError.js'\n\nexport const getRequestCollection = (req: PayloadRequest): Collection => {\n  const collectionSlug = req.routeParams?.collection\n\n  if (typeof collectionSlug !== 'string') {\n    throw new APIError(`No collection was specified`, 400)\n  }\n\n  const collection = req.payload.collections[collectionSlug]\n\n  if (!collection) {\n    throw new APIError(`Collection with the slug ${collectionSlug} was not found`, 404)\n  }\n\n  return collection\n}\n\nexport const getRequestCollectionWithID = <T extends boolean>(\n  req: PayloadRequest,\n  {\n    disableSanitize,\n    optionalID,\n  }: {\n    disableSanitize?: T\n    optionalID?: boolean\n  } = {},\n): {\n  collection: Collection\n  id: T extends true ? string : number | string\n} => {","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/utilities/getRequestEntity.ts#L1-L35","documentation":"Thrown by `getRequestCollection` when `req.routeParams.collection` is a string but does not match any registered collection in `req.payload.collections`. This means the slug in the URL does not correspond to a collection defined in the Payload config.","triggerScenarios":"A REST request targets `/api/:collection` where `:collection` is a slug that was never registered -- e.g. a typo, a deleted collection, or a slug from a different environment.","commonSituations":"Client hardcodes a collection slug that was renamed or removed in a config migration; an environment mismatch (staging has a collection production does not); the slug casing differs (e.g. `Media` vs `media`); a plugin that was supposed to register the collection is not loaded.","solutions":["Verify the collection slug in the request matches a collection defined in `config.collections`.","Check for slug casing -- Payload collection slugs are case-sensitive.","Ensure any plugin or module that registers the collection is properly imported in the config.","Confirm the same config is loaded across environments (no missing plugin imports).","If the collection was intentionally removed, update the client to stop referencing it."],"exampleFix":"// before -- slug mismatch\nawait fetch('/api/Media') // config defines slug: 'media' (lowercase)\n\n// after\nawait fetch('/api/media')","handlingStrategy":"type-guard","validationCode":"// Verify the collection slug is registered before making the request\nconst registeredSlugs = Object.keys(payload.collections)\nif (!registeredSlugs.includes(requestedSlug)) {\n  throw new Error(`Collection '${requestedSlug}' is not registered. Available: ${registeredSlugs.join(', ')}`)\n}","typeGuard":"const isRegisteredCollection = (slug, collections) => slug in collections","tryCatchPattern":"try {\n  await fetch(`/api/${slug}`)\n} catch (e) {\n  if (e instanceof APIError && e.message.includes('was not found')) {\n    // check config.collections for the correct slug\n  } else throw e\n}","preventionTips":["Validate collection slugs against the registered config before sending requests.","Keep collection slugs lowercase and consistent across environments.","Ensure all plugins that register collections are loaded in every environment.","Use the Local API to avoid URL construction errors."],"tags":["routing","collection","config","not-found"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}