Logstash HTTP output plugin

I'm trying to use the HTTP output plugin to send a PUT request to a URL but getting a 400 message, and I can't figure out what I'm messing up.
I'm using Logstash v8 running in a Docker container.

I'm able to successfully make a PUT request using Postman App. This is the HTTP code that Postman generates which I'm using to configure the HTTP plugin in Logstash

PUT /v2/conversation/account/accountid1122/sendMessage HTTP/1.1
Host: endpoint.testing.com
Authorization: my auth code
Content-Type: application/json
Content-Length: 257

{
    "recipients": [
        {
            "phone": "+1234567890",
            "firstName": "Test",
            "lastName": "Test"
        }
    ],
    "locationId": "myLocationID",
    "msg": "API Test!",
    "scheduledAt": null
}

My HTTP plugin looks like this:

http {
       http_method => "put"
       url => "https://endpoint.testing.com/v2/conversation/account/accountid1122/sendMessage"
       headers => {
          "Content-Type" => "application/json"
          "Authorization" => "MyAuthCode"
       }
       message => '{
          "recipients": [
              {
                  "phone": "1234567890",
              }
          ],
          "locationId": "myLocationID",
          "msg": "API Test!!",
          "scheduledAt": null
        }'
    }

Logstash is throwing 400 error.

Encountered non-2xx HTTP code 400 {:response_code=>400, :url=>"https://endpoint.testing.com/v2/conversation/account/accountid1122/sendMessage", :event=>#<LogStash::Event:0x76181d9a>

What am I messing up?

Also, is there a way for me to run the Logstash container with auto-config-reload and debug enabled?

I got auto-reload and debug working and seeing the following error in the debug logs:

[2023-10-08T13:20:54,205][DEBUG][org.apache.http.wire     ][main][1d48ee448c470bd49a6ba581e5729fb431ff04a6a255fc46a83462d071f31493] http-outgoing-0 << "{"code":400,"message":"Empty value for msg field not allowed"}"

Not sure why I'm getting that even though my msg field is set to "msg": "API Test!!"

I've also added format => "message" in my HTTP output plugin

Able to figure out the issue. Just needed to remove "Content-Type" => "application/json" from the headers parameter and set the content_type parameter separately.

Working config:

http {
        http_method => "put"
        url => "https://endpoint.testing.com/v2/conversation/account/accountid1122/sendMessage"
        headers => { "Authorization" => "MyAuthCode"}
        format => "message"
        content_type => "application/json"
        message => '{"msg":"API Test!!","recipients":[{"phone":"%{from}"}],"locationId":"myLocationID","scheduledAt":null}'
      }

Otherwise there were \r\n characters being inserted into the headers which was throwing off the put request.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.