{"record":{"id":"07c51cfac2281c76","repo":"kestra-io/kestra","slug":"couldn-t-parse-the-request-body","errorCode":null,"errorMessage":"Couldn't parse the request body","messagePattern":"Couldn't parse the request body","errorType":"exception","errorClass":"PebbleException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/io/kestra/core/runners/pebble/functions/HttpFunction.java","lineNumber":136,"sourceCode":"\n    private Map<String, List<String>> singleValueToListForHeaders(Map<String, Object> m) {\n        return m.entrySet().stream()\n            .map(e -> Map.entry(e.getKey(), e.getValue() instanceof String valueStr ? List.of(valueStr) : (List<String>) e.getValue()))\n            .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));\n    }\n\n    private HttpRequest.RequestBody toRequestBody(Map<String, Object> args, PebbleTemplate self, int lineNumber, String contentType) {\n        HttpRequest.RequestBody body;\n        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();\n        Class<T> bodyClass = (Class<T>) args.get(\"body\").getClass();\n        MessageBodyWriter<T> bodyWriter = defaultMessageBodyHandlerRegistry.findWriter(Argument.of(bodyClass), MediaType.of(contentType)).orElse(FALLBACK_CONTENT_WRITER);\n        bodyWriter.writeTo(Argument.of(bodyClass), MediaType.of(contentType), (T) args.get(\"body\"), new SimpleHttpHeaders(), byteArrayOutputStream);\n        try {\n            body = HttpRequest.RequestBody.from(\n                new ByteArrayEntity(byteArrayOutputStream.toByteArray(), ContentType.create(contentType))\n            );\n        } catch (IOException e) {\n            throw new PebbleException(e, \"Couldn't parse the request body\", lineNumber, self.getName());\n        }\n        return body;\n    }\n\n    private void throwIfMissingArgs(Map<String, Object> args, PebbleTemplate self, int lineNumber) {\n        if (!args.containsKey(\"uri\")) {\n            throw new PebbleException(null, \"The 'http' function expects an argument 'uri'.\", lineNumber, self.getName());\n        }\n    }\n\n    @Override\n    public List<String> getArgumentNames() {\n        return List.of(\"uri\", \"method\", \"query\", \"body\", \"contentType\", \"headers\", \"options\", \"accept\");\n    }\n\n    @Override\n    public Map<String, String> getArgumentDefaults() {\n        HashMap<String, String> defaults = new HashMap<>();","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/kestra-io/kestra/blob/823fada9274c4f9c251ea0a516460a4f7d958032/core/src/main/java/io/kestra/core/runners/pebble/functions/HttpFunction.java#L118-L154","documentation":"Thrown by 'http' while building the request body entity: after the body writer serializes the object into a byte array, constructing the Apache HC ByteArrayEntity with the given contentType raises an IOException. In practice a malformed contentType MIME string is the usual culprit.","triggerScenarios":"Passing a malformed contentType such as 'application//json', 'json', or an empty string to http together with a body.","commonSituations":"Typo or missing slash in the contentType, passing a file extension instead of a MIME type, or a templated contentType that rendered to an unexpected value.","solutions":["Use a valid MIME type string for contentType, e.g. 'application/json', 'application/yaml', 'text/plain'.","If contentType is templated, render it separately to confirm it resolves to a real MIME type.","Omit contentType to accept the 'application/json' default."],"exampleFix":"// before\n{{ http(uri, method='POST', body=payload, contentType='json') }}\n// after\n{{ http(uri, method='POST', body=payload, contentType='application/json') }}","handlingStrategy":"validation","validationCode":"{% set ct = contentType ?? 'application/json' %}{% if '/' not in ct %}{% set ct = 'application/json' %}{% endif %}{{ http(uri, method='POST', body=payload, contentType=ct) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass contentType as a full MIME type in type/subtype form.","Omit contentType unless you need a non-JSON type.","Render templated contentType values separately to confirm they are real MIME types."],"tags":["pebble","http","content-type","mime"],"backgroundTag":null,"analyzedSha":"823fada9274c4f9c251ea0a516460a4f7d958032","analyzedAt":"2026-08-14T06:15:17.947Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}