karatelabs/karate · error · RuntimeException
param() needs two arguments
Error message
param() needs two arguments
What it means
HttpRequestBuilder exposes param() to scripts as a two-argument invokable (name, value) that adds a URL query parameter. Called with fewer than two arguments it throws this RuntimeException, failing fast instead of adding a malformed parameter.
Solutions
- Pass both name and value: builder.param('page', '2')
- Build params from a map using the map-accepting overload or loop with explicit key/value
- Skip empty values in your loop instead of calling param() with them
- For flag-style parameters, pass an empty-string value explicitly: param('verbose', '')
Example fix
// before
builder.param("page"); // throws
// after
builder.param("page", "2"); Defensive patterns
Strategy: validation
Validate before calling
if (paramValue == null) throw new Error('query param ' + paramName + ' has no value');
builder.param(paramName, paramValue + ''); Type guard
function paramArgsOk(name, value) { return name != null && value != null; } Prevention
- Always pass (name, value) to param(); flag-style params should use an empty string value
- Validate dynamic param maps before iterating
- Convert values to strings explicitly so undefined doesn't drop the argument
When it happens
Trigger: Calling param() or param('page') with a single argument from a script; dynamic query-string construction where the value variable is undefined; confusing param(name, value) with param-getter methods elsewhere in the API.
Common situations: Building paginated/filtered requests where params come from a map or user input and some entries are missing; templated scripts where a placeholder failed to substitute; learners assuming param() with one arg sets a flag-style parameter.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- missing argument for multiPart()
- missing argument for file()
- missing argument for files()
- cache() requires (key, fn)
- header() needs two arguments
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/fb11154db5a45445.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/http/HttpRequestBuilder.java:730
}
return invoke();
};
}
private JavaInvokable header() {
return args -> {
if (args.length < 2) {
throw new RuntimeException("header() needs two arguments");
}
header(args[0] + "", args[1] + "");
return this;
};
}
private JavaInvokable param() {
return args -> {
if (args.length < 2) {
throw new RuntimeException("param() needs two arguments");
}
param(args[0] + "", args[1] + "");
return this;
};
}
/**
* The JS-facing plural forms of {@link #param} and {@link #header}. The Java
* {@link #params(Map)} takes a {@code Map<String, List<String>>} and replaces what was
* there, which is awkward to satisfy from JS - these accumulate and accept a scalar or a
* list per key, matching the {@code params} and {@code headers} keywords.
*/
private JavaInvokable params() {
return args -> {
if (args.length == 0 || !(args[0] instanceof Map<?, ?> map)) {
throw new RuntimeException("params() needs a map argument");
}
map.forEach((k, v) -> {View on GitHub (pinned to a22eb90246)