{"record":{"id":"7bcb73c488874bd0","repo":"RocketChat/Rocket.Chat","slug":"error-invalid-params-custom","errorCode":"error-invalid-params-custom","errorMessage":"error-invalid-params-custom","messagePattern":"error-invalid-params-custom","errorType":"exception","errorClass":"Meteor.Error","httpStatus":null,"severity":"error","filePath":"apps/meteor/server/api/v1/omnichannel/contact.ts","lineNumber":90,"sourceCode":"\t'omnichannel/contact.search',\n\t{\n\t\tauthRequired: true,\n\t\tpermissionsRequired: ['view-l-room'],\n\t},\n\t{\n\t\tasync get() {\n\t\t\tcheck(this.queryParams, {\n\t\t\t\temail: Match.Maybe(String),\n\t\t\t\tphone: Match.Maybe(String),\n\t\t\t\tcustom: Match.Maybe(String),\n\t\t\t});\n\t\t\tconst { email, phone, custom } = this.queryParams;\n\n\t\t\tlet customCF: { [k: string]: string } = {};\n\t\t\ttry {\n\t\t\t\tcustomCF = custom && JSON.parse(custom);\n\t\t\t} catch (e) {\n\t\t\t\tthrow new Meteor.Error('error-invalid-params-custom');\n\t\t\t}\n\n\t\t\tif (!email && !phone && !Object.keys(customCF).length) {\n\t\t\t\tthrow new Meteor.Error('error-invalid-params');\n\t\t\t}\n\n\t\t\tconst foundCF = await (async () => {\n\t\t\t\tif (!custom) {\n\t\t\t\t\treturn {};\n\t\t\t\t}\n\n\t\t\t\tconst cfIds = Object.keys(customCF);\n\n\t\t\t\tconst customFields = await LivechatCustomField.findMatchingCustomFieldsByIds(cfIds, 'visitor', true, {\n\t\t\t\t\tprojection: { _id: 1 },\n\t\t\t\t}).toArray();\n\n\t\t\t\treturn Object.fromEntries(customFields.map(({ _id }) => [`livechatData.${_id}`, new RegExp(escapeRegExp(customCF[_id]), 'i')]));","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/server/api/v1/omnichannel/contact.ts#L72-L108","documentation":"Thrown by GET /api/v1/omnichannel/contact.search when JSON.parse(custom) throws an exception. The custom query parameter is expected to be a JSON-encoded object of custom field key/value pairs. If it is not valid JSON, the parse fails and this error fires.","triggerScenarios":"Passing a custom query parameter that is malformed JSON — e.g., unquoted keys, single quotes instead of double quotes, trailing commas, or a non-JSON string format.","commonSituations":"Client constructs the custom parameter as a plain string instead of JSON; URL encoding breaks the JSON structure; client uses a different serialization format (e.g., key:value); copy-paste introduced invisible characters.","solutions":["Ensure the custom parameter is valid JSON (double-quoted keys and string values).","URL-encode the JSON string when passing it as a query parameter.","Validate the JSON client-side with JSON.parse before sending the request."],"exampleFix":"// before: malformed JSON in the custom param\nGET /api/v1/omnichannel/contact.search?custom={phone:123}\n// after: valid, URL-encoded JSON\nGET /api/v1/omnichannel/contact.search?custom=%7B%22phone%22%3A%22123%22%7D\n// decoded: {\"phone\":\"123\"}","handlingStrategy":"validation","validationCode":"// Validate the custom parameter is valid JSON before sending the request\nfunction buildContactSearchParams({ email, phone, custom }) {\n  const params = new URLSearchParams();\n  if (email) params.set('email', email);\n  if (phone) params.set('phone', phone);\n  if (custom) {\n    // Ensure custom is a valid JSON object\n    const customObj = typeof custom === 'string' ? JSON.parse(custom) : custom;\n    const customJson = JSON.stringify(customObj);\n    if (JSON.parse(customJson)) { // throws if invalid\n      params.set('custom', customJson);\n    }\n  }\n  return params;\n}","typeGuard":"function isValidCustomFieldJson(value: unknown): value is Record<string, string> {\n  if (typeof value !== 'string') return false;\n  try {\n    const parsed = JSON.parse(value);\n    return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed);\n  } catch {\n    return false;\n  }\n}","tryCatchPattern":"try {\n  await searchContact({ custom });\n} catch (e) {\n  if (e.error === 'error-invalid-params-custom') {\n    console.error('The custom parameter is not valid JSON. Use {\"key\":\"value\"} format.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Always JSON.stringify the custom field object before passing it as a query parameter.","URL-encode the JSON string to preserve special characters.","Validate with JSON.parse on the client side before sending."],"tags":["omnichannel","contact","validation","json"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}