{"record":{"id":"ac8f09c8bce6c6c3","repo":"crowdsecurity/crowdsec","slug":"invalid-type-for-body-t","errorCode":null,"errorMessage":"invalid type for body: %T","messagePattern":"invalid type for body: %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/exprhelpers/http.go","lineNumber":104,"sourceCode":"\n\treturn doHTTPRequest(http.MethodHead, uri, nil, nil)\n}\n\n// HTTPPost(url string, contentType string, body string) (*HTTPResponse, error)\nfunc HTTPPost(params ...any) (any, error) {\n\turi, ok := params[0].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for url: %T\", params[0])\n\t}\n\n\tcontentType, ok := params[1].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for contentType: %T\", params[1])\n\t}\n\n\tbody, ok := params[2].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for body: %T\", params[2])\n\t}\n\n\theaders := map[string]string{\"Content-Type\": contentType}\n\n\treturn doHTTPRequest(http.MethodPost, uri, headers, strings.NewReader(body))\n}\n\n// HTTPRequest(method string, url string, headers map[string]any, body string) (*HTTPResponse, error)\nfunc HTTPRequest(params ...any) (any, error) {\n\tmethod, ok := params[0].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for method: %T\", params[0])\n\t}\n\n\turi, ok := params[1].(string)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"invalid type for url: %T\", params[1])\n\t}","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/exprhelpers/http.go#L86-L122","documentation":"HTTPPost asserts its third parameter (body) to string before sending the request. This error means the body argument was not a string — the helper writes the body via strings.NewReader, so only strings are accepted.","triggerScenarios":"HTTPPost(url, contentType, evt.payload) where payload is a map, a number, nil, or raw bytes; passing a structured object instead of a serialized string.","commonSituations":"Passing a parsed JSON object (map[string]interface{}) instead of a serialized JSON string; nil payload field; numeric payload without conversion.","solutions":["Serialize structured data to a JSON string before passing it (e.g. via a JSON marshal helper in the expression)","Convert numbers or other scalars to string form","Ensure the payload field is populated and string-typed","Check the %T in the error to identify the actual body type"],"exampleFix":"// before\nHTTPPost(url, \"application/json\", evt.data) // evt.data is a map\n// after\nHTTPPost(url, \"application/json\", ToJSON(evt.data))","handlingStrategy":"validation","validationCode":"// serialize before sending:\n// HTTPPost(url, \"application/json\", ToJSON(evt.data))","typeGuard":"func isString(v interface{}) bool { _, ok := v.(string); return ok }","tryCatchPattern":null,"preventionTips":["Always serialize maps/objects to JSON strings before POSTing","Convert numeric payloads to strings","Confirm the payload field is populated and string-typed"],"tags":["expr","http","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}