# Not able to execute http request in Filter with JSON Payload

**URL:** <https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822>\
**Category:** Logstash\
**Created:** [November 22, 2018, 8:29am UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822 "2018-11-22T08:29:41Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [November 22, 2018, 8:29am UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/1 "2018-11-22T08:29:42Z")

</div>

Hi

Not able to execute http request in Filter with JSON Payload  
Here how my conf file looks like

```auto
rest {
   request => {
     url =>"https://abc.com"       
     method => "post"                  
  headers => {
   	"Authorization" => "%{access}"
   	"Content-Type" => "application/json"
   	}

     params => '{
   "reportRequests" :
   [{
   		"checkid" : "2345678",
   		"dateRanges" : [{
   				"endDate" : "2018-11-12",
   				"startDate" : "2018-11-01"
   			}
   		]
   	}
   ]
}'
   }
   json => true                         
   target => "my_key"                  

 }

```

This is the error i am getting

`

> fieldViolations": [\n {\n "description": "Invalid JSON payload received. Unknown name \"\": Root element must be a message."

The exact body works perfectly in POSTMAN, but here it does not work. Looks like something is missing params/body. Please suggest the right syntax or such feature is not supported?

`

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [November 22, 2018, 2:00pm UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/2 "2018-11-22T14:00:31Z")

</div>

Hi

Did anyone try this kind of payload in the params or body?

Thanks

---

<div class="post-metadata">

**Author:** ![Eniqmatic](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@Eniqmatic](https://discuss.elastic.co/u/Eniqmatic)\
**Post date:** [November 22, 2018, 3:26pm UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/3 "2018-11-22T15:26:31Z")

</div>

Can you post the full raw input?

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [November 22, 2018, 4:00pm UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/4 "2018-11-22T16:00:16Z")

</div>

Hi, Thanks for your response. Here is the full sample conf file

> input {  
> http\_poller{  
> urls =\> {  
> http\_request =\> {  
> method =\> POST  
> url =\>"[https://www.xyz.com](https://www.xyz.com)"  
> }  
> }
> 
> ```
> }
> 
> ```
> 
> }
> 
> filter {
> 
> rest {  
> request =\> {  
> url =\>"[https://abc.com](https://abc.com)"  
> method =\> "post"  
> headers =\> {  
> "Authorization" =\> "%{access}"  
> "Content-Type" =\> "application/json"  
> }
> 
> ```
> params => '{
> 
> ```
> 
> "reportRequests" :  
> [{  
> "checkid" : "2345678",  
> "dateRanges" : [{  
> "endDate" : "2018-11-12",  
> "startDate" : "2018-11-01"  
> }  
> ]  
> }  
> ]  
> }'  
> }  
> json =\> true  
> target =\> "my\_key"
> 
> }
> 
> }
> 
> output {
> 
> elasticsearch....
> 
> }

---

<div class="post-metadata">

**Author:** ![Eniqmatic](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@Eniqmatic](https://discuss.elastic.co/u/Eniqmatic)\
**Post date:** [November 23, 2018, 8:07am UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/5 "2018-11-23T08:07:55Z")

</div>

Sorry I mean can you post some raw input lines? Can we see the JSON message you are trying to input?

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [November 23, 2018, 9:59am UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/6 "2018-11-23T09:59:54Z")

</div>

Hi

From the input, i am hitting the URL, wherein i get the token for authorization of REST URL used in filter.

There response from input looks like this

```
{
    "access": "ya29.GlxdBqDTNQNJ4qHBFQVr3byMTmFofKKrsoZ3tM6XCDQ-W3ysrjOL9bl_4hGwAhirD-YHgtTtFbcUjt6jlsR-dpTxsIn4Hw6Fpnt_r0IAi9wq-",
    "scope": "https://abc.com",
}

```

This access i go and pass on to the filter section as %{access}

I hope you are looking for the same

Thanks!

---

<div class="post-metadata">

**Author:** ![Eniqmatic](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@Eniqmatic](https://discuss.elastic.co/u/Eniqmatic)\
**Post date:** [November 23, 2018, 10:21am UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/7 "2018-11-23T10:21:40Z")

</div>

Your error mentions the field "description" - where does that field come from?

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [November 23, 2018, 11:57am UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/8 "2018-11-23T11:57:44Z")

</div>

Hi

Below in code quote there is the complete error message from the log file.I do not have as such description field/event in source, that description is given by the API service to describe the error.

I think it will be nicer if you have any working conf file with REST Filter which uses method as 'post" and while posting it uses body to post the message to get the response.

Here the body should act as complete json, if you have any working example for REST filter then i think it can solve my problem

Thanks

> {  
> : request = \> [: post, "[https://abc.com](https://abc.com)", {  
> : headers = \> {  
> "Authorization" = \> "ya29.GlxdBqDTNQNJ4qHBFQVr3byMTmFofKKrsoZ3tM6XCDQ-W3ysrjOL9bl\_4hGwAhirD-YHgtTtFbcUjt6jlsR-dpTxsIn4Hw6Fpnt\_r0IAi9wq-"  
> },  
> : body = \> ""{\n\t'reportRequests' :\n\t[{\n\t\t\t'checkid' : '2345678',\n\t\t\t'dateRanges' : [{\n\t\t\t\t\t'endDate' : '2018-11-12',\n\t\t\t\t\t'startDate' : '2018-11-01'\n\t\t\t\t}\n\t\t\t],}""  
> }  
> ],  
> : json = \> true,  
> : code = \> 400,  
> : body = \> "{\n "error": {\n "code": 400,\n "message": "Invalid JSON payload received. Unknown name \"\": Root element must be a message.",\n "status": "INVALID\_ARGUMENT",\n "details": [\n {\n "@type": "abc.com.rpc.BadRequest",\n "fieldViolations": [\n {\n "description": "Invalid JSON payload received. Unknown name \"\": Root element must be a message."\n }\n]\n }\n ]\n }\n}\n",  
> : client\_error = \> nil  
> }

---

<div class="post-metadata">

**Author:** ![Eniqmatic](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@Eniqmatic](https://discuss.elastic.co/u/Eniqmatic)\
**Post date:** [November 23, 2018, 12:01pm UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/9 "2018-11-23T12:01:18Z")

</div>

Ah, it looks like your body is incorrect, are you manually specifying the line breaks in the body?

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [November 23, 2018, 12:32pm UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/10 "2018-11-23T12:32:48Z")

</div>

Yes from the error response i am getting that body is wrong.  
But what is the correct way to define the body with rest filter?

As asked in my previous message, do you have any working rest filter conf file,which helps to define the right body...

Thanks!

---

<div class="post-metadata">

**Author:** ![Eniqmatic](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@Eniqmatic](https://discuss.elastic.co/u/Eniqmatic)\
**Post date:** [November 23, 2018, 1:05pm UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/11 "2018-11-23T13:05:30Z")

</div>

This is how you do a HTTP-Poller request - Note your header will not work because you do not have a field called %{access} yet - you need to input this manually

```
input {
  http_poller {
    urls => {
      "request" => {
        method => POST
        url => "https://abc.com"
        headers => {
"Authorization" => "%{access}"
"Content-Type" => "application/json"
        }
      body => '{"password":"myPassword","userName":"yourUsername"}'
     }
    }
    request_timeout => 10
    codec => "json"
    metadata_target => "http_poller_metadata"
  }
}
```

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [November 23, 2018, 2:56pm UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/12 "2018-11-23T14:56:04Z")

</div>

I think there is a huge disconnect.  
My http\_poller have no issues, i have used this input in many cases.

I have problem with rest filter, which is not a official filter, i got it from Github. I am looking for example on rest filter

> **[lucashenning/logstash-filter-rest](https://github.com/lucashenning/logstash-filter-rest)**
>
> REST Filter for Logstash. Contribute to lucashenning/logstash-filter-rest development by creating an account on GitHub.

Please let me know if you have a working example of rest filter with method as post and message as json body

Thanks

---

<div class="post-metadata">

**Author:** ![Eniqmatic](https://avatars.discourse-cdn.com/v4/letter/e/ea5d25/32.png) [@Eniqmatic](https://discuss.elastic.co/u/Eniqmatic)\
**Post date:** [November 23, 2018, 3:02pm UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/13 "2018-11-23T15:02:37Z")

</div>

Ah I see, I do not have any experience of this plugin unfortunately. I see that you are trying to do a nested body which does not look to be supported, I think this is the issue.

---

<div class="post-metadata">

**Author:** ![rkhapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rkhapre/32/48333_2.png) [@rkhapre](https://discuss.elastic.co/u/rkhapre)\
**Post date:** [November 23, 2018, 3:36pm UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/14 "2018-11-23T15:36:33Z")

</div>

okay. I feel somehow it should be possible. By looking the filter plugin description, looks like it is possible. But not sure why its not working

I am going to take a different route by pinging the URL with ruby filter.  
Thanks for your time

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 21, 2018, 3:36pm UTC](https://discuss.elastic.co/t/not-able-to-execute-http-request-in-filter-with-json-payload/157822/15 "2018-12-21T15:36:39Z")

</div>

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