{"record":{"id":"1be8aa17721f3e4a","repo":"RocketChat/Rocket.Chat","slug":"the-name-parameter-must-be-a-valid-date","errorCode":null,"errorMessage":"The \"${name}\" parameter must be a valid date.","messagePattern":"The \"(.+?)\" parameter must be a valid date\\.","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"apps/meteor/ee/server/api/audit.ts","lineNumber":408,"sourceCode":"\t},\n\trequired: ['messages', 'success'],\n\tadditionalProperties: false,\n});\n\nconst auditErrorResponseSchema = ajv.compile({\n\ttype: 'object',\n\tproperties: {\n\t\tsuccess: { type: 'boolean', enum: [false] },\n\t\terror: { type: 'string' },\n\t\terrorType: { type: 'string' },\n\t},\n\trequired: ['success', 'error'],\n});\n\nconst parseDateOrFail = (value: string, name: string): Date => {\n\tconst ts = Date.parse(value);\n\tif (Number.isNaN(ts)) {\n\t\tthrow new Error(`The \"${name}\" parameter must be a valid date.`);\n\t}\n\treturn new Date(ts);\n};\n\nAPI.v1.get(\n\t'audit.auditions',\n\t{\n\t\tauthRequired: true,\n\t\tpermissionsRequired: ['can-audit-log'],\n\t\tquery: isAuditAuditionsProps,\n\t\tlicense: ['auditing'],\n\t\trateLimiterOptions: { numRequestsAllowed: 10, intervalTimeInMS: 60000 },\n\t\tresponse: {\n\t\t\t200: auditAuditionsResponseSchema,\n\t\t\t400: auditErrorResponseSchema,\n\t\t\t401: validateUnauthorizedErrorResponse,\n\t\t\t403: validateForbiddenErrorResponse,\n\t\t},","sourceCodeStart":390,"sourceCodeEnd":426,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/e4b8178b205510181a96ceefee043d0abcd13e5a/apps/meteor/ee/server/api/audit.ts#L390-L426","documentation":"Error thrown by parseDateOrFail in the EE audit REST API when the startDate/endDate parameter fails Date.parse (NaN). Used by audit.auditions (query params) and the audit endpoints (body params); the message names the offending parameter, e.g. `The \"startDate\" parameter must be a valid date.` The request fails with a 400 instead of running the audit query.","triggerScenarios":"GET /v1/audit.auditions?startDate=2024-13-01&endDate=... (invalid month), empty or non-ISO strings like 'yesterday', '2024/06/01' on strict parsers, or a date already serialized with NaN on the client.","commonSituations":"Clients building date strings by hand instead of toISOString(); locale-formatted dates (dd/MM/yyyy); timezone suffixes missing or malformed; passing epoch numbers as strings.","solutions":["Send ISO-8601 strings produced by date.toISOString(), e.g. 2024-06-01T00:00:00.000Z.","Validate with Date.parse on the client before sending and fix the construction of the string.","Check for accidental URL-encoding damage (colons/plus signs mangled) when dates travel in query strings."],"exampleFix":"// before\nGET /v1/audit.auditions?startDate=01/06/2024&endDate=30/06/2024 // 400\n\n// after\nGET /v1/audit.auditions?startDate=2024-06-01T00:00:00.000Z&endDate=2024-06-30T23:59:59.999Z","handlingStrategy":"validation","validationCode":"const isValidDateParam = (value: string): boolean => !Number.isNaN(Date.parse(value));\n\nconst toIsoParam = (d: Date): string => d.toISOString(); // always valid","typeGuard":"const isInvalidDateParamError = (error: unknown): boolean =>\n\tBoolean(error instanceof Error && /parameter must be a valid date/.test(error.message));","tryCatchPattern":"try {\n\tconst result = await GET('audit.auditions')({ startDate, endDate });\n} catch (error) {\n\tif (isInvalidDateParamError(error)) {\n\t\t// fix param construction: re-encode via toISOString() and resend once\n\t\tthrow new BadRequestError(error.message);\n\t}\n\tthrow error;\n}","preventionTips":["Always serialize date params with date.toISOString(), never template strings or locale formats.","Run Date.parse over each date param in a request wrapper before sending.","Encode query strings properly so timezone colons/offsets survive transport."],"tags":["ee","audit","date-validation","rest-api"],"backgroundTag":"invalid-date-format","analyzedSha":"e4b8178b205510181a96ceefee043d0abcd13e5a","analyzedAt":"2026-08-18T15:26:39.429Z","contentChangedAt":"2026-08-18T15:26:39.429Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}