Recently setup a lambda behind an ALB and attempted to make GET requests resulting in error message 'The variables search parameter contains invalid JSON.'
Example query params
queryStringParameters: {
operationName: 'product',
query: example query',
variables:
'%7B%22productId%22%3A%22756817%22%2C%22countryCode%22%3A%22GB%22%2C%22currencyCode%22%3A%22GBP%22%7D',
}
decoding the value via decodeURIComponent solved the issue.
parseQueryParams(event) {
const params = new URLSearchParams();
for (const [key, value] of Object.entries((event.queryStringParameters as Record<string, string>) ?? {})) {
params.append(key, decodeURIComponent(value) ?? '');
}
for (const [key, value] of Object.entries(
(event.multiValueQueryStringParameters as Record<string, string> | undefined) ?? {},
)) {
for (const v of value ?? []) {
params.append(key, v);
}
}
return params.toString();
}
Recently setup a lambda behind an ALB and attempted to make GET requests resulting in error message 'The variables search parameter contains invalid JSON.'
Example query params
decoding the value via decodeURIComponent solved the issue.