karatelabs/karate · error · RuntimeException
body() needs at least one argument
Error message
body() needs at least one argument
What it means
Arity guard in HttpRequestBuilder's body() JS binding: setting the request body requires at least one argument (the body value, converted downstream). Fires when builder body() is chained with no arguments.
Solutions
- Pass a value explicitly: `body({ a: 1 })`, `body('text')`, `body(xmlNode)`.
- Check the variable is defined before the call: `if (payload != null) body(payload)`.
- If you truly want no body, simply omit the body() call.
- For structured payloads use request/body keywords or pass a string/Map/List which the builder converts.
-
Example fix
// before var payload = /* may be undefined */; body(payload) // after if (payload != null) body(payload)
Defensive patterns
Strategy: validation
Validate before calling
if (payload != null) builder.body(payload);
Type guard
function hasBody(v) { return v !== undefined && v !== null; } Try / catch
try { builder.body(p); } catch (e) { if (('' + e).includes('at least one argument')) logger.warn('skipping body, payload undefined'); else throw e; } Prevention
- Check payload variables for undefined before body()
- Omit body() entirely when no body is intended
- Build payloads defensively so intermediate steps cannot return undefined
When it happens
Trigger: Calling `body()` with zero arguments, e.g. a JS variable holding the payload is undefined: `body(payload)` where payload is undefined collapses to no argument in the JS-to-Java bridge.
Common situations: Payload built by a preceding step that failed or returned null/undefined; forgetting to pass the request body in a generated request script.
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
- params() needs a map argument
- headers() needs a map argument
- read() needs at least one argument
- sysenv() needs the environment-variable name
- sysprop() needs the property name
AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12).
Data as JSON: /api/errors/c54333097c543ec3.
Report an issue: GitHub.
Appendix: source
Thrown at karate-core/src/main/java/io/karatelabs/http/HttpRequestBuilder.java:788
return this;
};
}
private JavaInvokable path() {
return args -> {
for (Object arg : args) {
if (arg != null) {
path(arg + "");
}
}
return this;
};
}
private JavaInvokable body() {
return args -> {
if (args.length == 0) {
throw new RuntimeException("body() needs at least one argument");
}
body(args[0]);
return this;
};
}
@Override
public Object jsGet(String key) {
switch (key) {
case "get":
case "post":
case "put":
case "delete":
case "head":
case "options":
case "trace":
case "connect":
case "patch":View on GitHub (pinned to a22eb90246)