RocketChat/Rocket.Chat · error · Meteor.Error
error-invalid-params-custom
error-invalid-params-custom
Error message
error-invalid-params-custom
What it means
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.
Source
Thrown at apps/meteor/server/api/v1/omnichannel/contact.ts:90
'omnichannel/contact.search',
{
authRequired: true,
permissionsRequired: ['view-l-room'],
},
{
async get() {
check(this.queryParams, {
email: Match.Maybe(String),
phone: Match.Maybe(String),
custom: Match.Maybe(String),
});
const { email, phone, custom } = this.queryParams;
let customCF: { [k: string]: string } = {};
try {
customCF = custom && JSON.parse(custom);
} catch (e) {
throw new Meteor.Error('error-invalid-params-custom');
}
if (!email && !phone && !Object.keys(customCF).length) {
throw new Meteor.Error('error-invalid-params');
}
const foundCF = await (async () => {
if (!custom) {
return {};
}
const cfIds = Object.keys(customCF);
const customFields = await LivechatCustomField.findMatchingCustomFieldsByIds(cfIds, 'visitor', true, {
projection: { _id: 1 },
}).toArray();
return Object.fromEntries(customFields.map(({ _id }) => [`livechatData.${_id}`, new RegExp(escapeRegExp(customCF[_id]), 'i')]));View on GitHub (pinned to f9d3ec372b)
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.
Example fix
// before: malformed JSON in the custom param
GET /api/v1/omnichannel/contact.search?custom={phone:123}
// after: valid, URL-encoded JSON
GET /api/v1/omnichannel/contact.search?custom=%7B%22phone%22%3A%22123%22%7D
// decoded: {"phone":"123"} Defensive patterns
Strategy: validation
Validate before calling
// Validate the custom parameter is valid JSON before sending the request
function buildContactSearchParams({ email, phone, custom }) {
const params = new URLSearchParams();
if (email) params.set('email', email);
if (phone) params.set('phone', phone);
if (custom) {
// Ensure custom is a valid JSON object
const customObj = typeof custom === 'string' ? JSON.parse(custom) : custom;
const customJson = JSON.stringify(customObj);
if (JSON.parse(customJson)) { // throws if invalid
params.set('custom', customJson);
}
}
return params;
} Type guard
function isValidCustomFieldJson(value: unknown): value is Record<string, string> {
if (typeof value !== 'string') return false;
try {
const parsed = JSON.parse(value);
return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed);
} catch {
return false;
}
} Try / catch
try {
await searchContact({ custom });
} catch (e) {
if (e.error === 'error-invalid-params-custom') {
console.error('The custom parameter is not valid JSON. Use {"key":"value"} format.');
return;
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- error-invalid-params
- Failed to parse app.json: ${e instanceof Error ? e.message :
- error-invalid-sla
- error-invalid-user
- Invalid type
AI-assisted analysis of RocketChat/Rocket.Chat@f9d3ec372b (2026-08-12).
Data as JSON: /api/errors/7bcb73c488874bd0.
Report an issue: GitHub.