{"record":{"id":"6b42cd4a00d209bb","repo":"payloadcms/payload","slug":"no-collection-was-specified","errorCode":null,"errorMessage":"No collection was specified","messagePattern":"No collection was specified","errorType":"exception","errorClass":"APIError","httpStatus":400,"severity":"error","filePath":"packages/payload/src/utilities/getRequestEntity.ts","lineNumber":11,"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","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/utilities/getRequestEntity.ts#L1-L29","documentation":"Thrown by `getRequestCollection` when `req.routeParams.collection` is absent or not a string. This utility resolves the target collection from the request route parameters on every collection-scoped REST endpoint.","triggerScenarios":"A request reaches a collection-resolution path (e.g. via `getRequestCollection` or `getRequestCollectionWithID`) but the route was matched without populating `routeParams.collection`. This typically indicates a misconfigured custom route, a middleware that strips route params, or an internal call missing the param.","commonSituations":"A custom Express/Next handler forwards to Payload REST layer without setting route params; a middleware or proxy rewrote the URL and dropped the collection segment; an internal Local API call constructed a synthetic `PayloadRequest` without `routeParams`; a misconfigured custom route pattern that does not capture the collection slug.","solutions":["Ensure the request URL includes the collection slug segment and the route pattern captures it into `routeParams.collection`.","If calling the REST layer programmatically, set `req.routeParams = { collection: 'yourSlug' }` on the synthetic request.","Verify no middleware mutates or clears `req.routeParams` before Payload processes the request.","Use the Local API (`payload.find`, `payload.create`, etc.) instead of constructing raw requests when possible."],"exampleFix":"// before -- custom handler forwards without routeParams\napp.post('/api/media', (req, res) => payloadRestHandler(req, res)) // no routeParams.collection\n\n// after\napp.post('/api/:collection', (req, res, next) => {\n  req.routeParams = { collection: req.params.collection }\n  next()\n})","handlingStrategy":"validation","validationCode":"// Before forwarding to Payload REST, ensure routeParams.collection is set\nif (typeof req.routeParams?.collection !== 'string') {\n  throw new Error('Missing collection slug in route params')\n}","typeGuard":"const hasCollectionParam = (req) =>\n  typeof req.routeParams?.collection === 'string'","tryCatchPattern":"try {\n  collection = getRequestCollection(req)\n} catch (e) {\n  if (e instanceof APIError && e.message === 'No collection was specified') {\n    // set req.routeParams.collection and retry, or return 400\n  } else throw e\n}","preventionTips":["Always set req.routeParams.collection when constructing synthetic requests.","Use the Local API for programmatic operations to avoid manual route param setup.","Verify custom route patterns capture the collection slug."],"tags":["routing","collection","request","config"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}