# Error in using EXEC filter for curl

**URL:** <https://discuss.elastic.co/t/error-in-using-exec-filter-for-curl/282459>\
**Category:** Logstash\
**Created:** [August 25, 2021, 8:03am UTC](https://discuss.elastic.co/t/error-in-using-exec-filter-for-curl/282459 "2021-08-25T08:03:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gauti](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@Gauti](https://discuss.elastic.co/u/Gauti)\
**Post date:** [August 25, 2021, 8:03am UTC](https://discuss.elastic.co/t/error-in-using-exec-filter-for-curl/282459/1 "2021-08-25T08:03:32Z")

</div>

Hi All,

We have a scenario where through curl we are getting some output, when tried the curl command directly we are getting the output.

```auto
curl --location --request POST 'https://demo.cloud.ie/api/v2/analytics/conversations/aggregates/query'
 --header 'Authorization: Bearer Ejd22Vdsfergvvsdrgar' --header 'Cont
ent-Type: application/json' --data '{ "interval": "2021-08-09T18:30:00.000Z/2021-08-10T18:30:00.000Z", "metrics": [ "nOffered", "tAn
swered", "tAbandon" ] } '

```

And this is the output

```auto
{"results":[{"group":{"mediaType":"chat"},"data":[{"interval":"2021-08-09T18:30:00.000Z/2021-08-10T18:30:00.000Z","metrics":[{"metric":
"nOffered","stats":{"count":5}},{"metric":"tAnswered","stats":{"max":8500505,"min":2966,"count":5,"sum":17101288}}]}]},{"group":{"media
Type":"email"},"data":[{"interval":"2021-08-09T18:30:00.000Z/2021-08-10T18:30:00.000Z","metrics":[{"metric":"nOffered","stats":{"count"
:8}},{"metric":"tAnswered","stats":{"max":7619543,"min":6446,"count":8,"sum":11067681}}]}]},{"group":{"mediaType":"voice"},"data":[{"in
terval":"2021-08-09T18:30:00.000Z/2021-08-10T18:30:00.000Z","metrics":[{"metric":"nOffered","stats":{"count":30}},{"metric":"tAbandon",
"stats":{"max":143658,"min":1460,"count":15,"sum":457995}},{"metric":"tAnswered","stats":{"max":40646,"min":3107,"count":14,"sum":14216
0}}]}]}]}

```

When i try putting the same into logstash using exec filter i am getting error, here is my logstash input filter

```auto
input {
    exec {
command => " curl --location --request POST 'https://demo.cloud.ie/api/v2/analytics/conversations/aggregates/query'
 --header 'Authorization: Bearer Ejd22Vdsfergvvsdrgar' --header 'Cont
ent-Type: application/json' --data '{ "interval": "2021-08-09T18:30:00.000Z/2021-08-10T18:30:00.000Z", "metrics": [ "nOffered", "tAn
swered", "tAbandon" ] } ' "
schedule => "* * * * *"
}
}

```

While running this i am getting error like below

```auto
[2021-08-25T08:01:03,931][INFO][logstash.runner] Starting Logstash {"logstash.version"=>"7.13.4", "jruby.version"=>"jruby 9.
2.16.0 (2.5.7) 2021-03-03 f82228dc32 OpenJDK 64-Bit Server VM 11.0.11+9 on 11.0.11+9 +indy +jit [linux-x86_64]"}
[2021-08-25T08:01:04,376][WARN][logstash.config.source.multilocal] Ignoring the 'pipelines.yml' file because modules or command line o
ptions are specified
[2021-08-25T08:01:05,382][INFO][logstash.agent] Successfully started Logstash API endpoint {:port=>9601}
[2021-08-25T08:01:05,700][ERROR][logstash.agent] Failed to execute action {:action=>LogStash::PipelineAction::Create/pipelin
e_id:main, :exception=>"LogStash::ConfigurationError", :message=>"Expected one of [\\t\\r\\n], \"#\", \"{\", \"}\" at line 3, column 3
04 (byte 325) after input {\r\n exec {\r\n command => \"curl --location --request POST 'https://api.mypurecloud.ie/api/v2/ana
lytics/conversations/aggregates/query' --header 'Authorization: Bearer Ejd22Vlgr-KPzRFUlF7YomzTxbIeCgiFtMJbOtj-ev4PMQCgX5wwuI3KGbMEgRYe
kFmGgZiugSgdpL6kNmKT7Q' --header 'Content-Type: application/json' --data '{ \"", :backtrace=>["/usr/share/logstash/logstash-core/lib/
logstash/compiler.rb:32:in `compile_imperative'", "org/logstash/execution/AbstractPipelineExt.java:187:in `initialize'", "org/logstash/
execution/JavaBasePipelineExt.java:72:in `initialize'", "/usr/share/logstash/logstash-core/lib/logstash/java_pipeline.rb:47:in `initial
ize'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline_action/create.rb:52:in `execute'", "/usr/share/logstash/logstash-core/l
ib/logstash/agent.rb:389:in `block in converge_state'"]}
[2021-08-25T08:01:05,792][INFO][logstash.runner] Logstash shut down.
[2021-08-25T08:01:05,800][FATAL][org.logstash.Logstash] Logstash stopped processing because of an error: (SystemExit) exit
org.jruby.exceptions.SystemExit: (SystemExit) exit
at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:747) ~[jruby-complete-9.2.16.0.jar:?]
at org.jruby.RubyKernel.exit(org/jruby/RubyKernel.java:710) ~[jruby-complete-9.2.16.0.jar:?]
at usr.share.logstash.lib.bootstrap.environment.<main>(/usr/share/logstash/lib/bootstrap/environment.rb:89) ~[?:?]

```

Any advice, where i'm going wrong?

Thanks  
Gautham

---

<div class="post-metadata">

**Author:** ![Cad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cad/32/86661_2.png) [@Cad](https://discuss.elastic.co/u/Cad)\
**Post date:** [August 25, 2021, 8:58am UTC](https://discuss.elastic.co/t/error-in-using-exec-filter-for-curl/282459/2 "2021-08-25T08:58:32Z")

</div>

Hi,

You have to escape all double quotes of the command.

---

<div class="post-metadata">

**Author:** ![Gauti](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@Gauti](https://discuss.elastic.co/u/Gauti)\
**Post date:** [August 25, 2021, 4:05pm UTC](https://discuss.elastic.co/t/error-in-using-exec-filter-for-curl/282459/3 "2021-08-25T16:05:08Z")

</div>

Hi @Cad

We tried but our source system is not accepting the query without double quotes.

`{"message":"The request could not be understood by the server due to malformed syntax.","code":"bad.request","status":400,"contextId":"`

Any way where we can keep the double quotes and run the curl in logstash?

Thanks  
Gautham

---

<div class="post-metadata">

**Author:** ![Cad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cad/32/86661_2.png) [@Cad](https://discuss.elastic.co/u/Cad)\
**Post date:** [August 25, 2021, 7:29pm UTC](https://discuss.elastic.co/t/error-in-using-exec-filter-for-curl/282459/4 "2021-08-25T19:29:35Z")

</div>

On this previous topic [https://discuss.elastic.co/t/logstash-http-poller-body-escape-double-and-single-quotation-marks/282039/2?u=cad](https://discuss.elastic.co/t/logstash-http-poller-body-escape-double-and-single-quotation-marks/282039/2) someone suggest to use unicode. It's on a different plugin but you should give a try. The unicode for quotes is `\u0022`

Cad.

---

<div class="post-metadata">

**Author:** ![Gauti](https://avatars.discourse-cdn.com/v4/letter/g/cdc98d/32.png) [@Gauti](https://discuss.elastic.co/u/Gauti)\
**Post date:** [August 27, 2021, 5:05am UTC](https://discuss.elastic.co/t/error-in-using-exec-filter-for-curl/282459/5 "2021-08-27T05:05:36Z")

</div>

@Cad Tried it, but no luck ☹

Thanks  
Gautham

---

<div class="post-metadata">

**Author:** ![Cad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cad/32/86661_2.png) [@Cad](https://discuss.elastic.co/u/Cad)\
**Post date:** [August 27, 2021, 7:27am UTC](https://discuss.elastic.co/t/error-in-using-exec-filter-for-curl/282459/6 "2021-08-27T07:27:35Z")

</div>

According to [this source](https://stackoverflow.com/questions/40869203/how-do-i-escape-strings-in-logstash) the following code should work.

```auto
' curl --location --request POST "https://demo.cloud.ie/api/v2/analytics/conversations/aggregates/query" --header "Authorization: Bearer Ejd22Vdsfergvvsdrgar" --header "Content-Type: application/json" --data "{ \"interval\": \"2021-08-09T18:30:00.000Z/2021-08-10T18:30:00.000Z\", \"metrics\": [\"nOffered\", \"tAnswered\", \"tAbandon\"] } " '

```

---

<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:** [September 24, 2021, 7:28am UTC](https://discuss.elastic.co/t/error-in-using-exec-filter-for-curl/282459/7 "2021-09-24T07:28:02Z")

</div>

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