# Curl -x put content-type: application/json throwing error

**URL:** https://discuss.elastic.co/t/curl-x-put-content-type-application-json-throwing-error/296868
**Category:** Elasticsearch
**Created:** [February 10, 2022, 4:00pm UTC](https://discuss.elastic.co/t/curl-x-put-content-type-application-json-throwing-error/296868 "2022-02-10T16:00:36Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![byoungman](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@byoungman](https://discuss.elastic.co/u/byoungman)
#### Post date: [February 10, 2022, 4:00pm UTC](https://discuss.elastic.co/t/curl-x-put-content-type-application-json-throwing-error/296868/1 "2022-02-10T16:00:36Z")

</div>

I have an Elasticsearch instance that has reached it's default max shards of 1000 and now I'm trying to increase that number using curl but am running into an issue with the -h content-type declaration.

Here is my curl statement--

curl -X PUT "localhost:9200/\_cluster/settings?pretty" -H 'Content-Type: application/json' -d' { "persistent" : { "cluster.max\_shards\_per\_node" : "3000" }}'

This is the response that I am getting back--

{  
"error" : "Content-Type header [application/x-www-form-urlencoded] is not supported",  
"status" : 406  
}

I went to a curl test site for posting json and copied the -h switch directly into my curl statement and I'm still getting this error.

Even though this isn't a frequently used instance I need to get it back up because it is in a production environment.

TIA  
Bill Youngman

---

<div class="post-metadata">

### Author: ![byoungman](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@byoungman](https://discuss.elastic.co/u/byoungman)
#### Post date: [February 10, 2022, 5:09pm UTC](https://discuss.elastic.co/t/curl-x-put-content-type-application-json-throwing-error/296868/2 "2022-02-10T17:09:51Z")

</div>

Update--

I changed my curl command to--

```auto
curl -X PUT localhost:9200/_cluster/settings?pretty -H "Content-Type: application/json" -d' { "persistent" : {"cluster.max_shards_per_node" : "3000" }}'

```

Error-

```auto
{
  "error" : {
    "root_cause" : [
      {
        "type" : "json_parse_exception",
        "reason" : "Unexpected character (''' (code 39)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 1, column: 2]"
      }
    ],
    "type" : "json_parse_exception",
    "reason" : "Unexpected character (''' (code 39)): expected a valid value (JSON String, Number, Array, Object or token 'null', 'true' or 'false')\n at [Source: (org.elasticsearch.common.io.stream.ByteBufferStreamInput); line: 1, column:2]"
  },
  "status" : 400
}
curl: (3) unmatched brace in URL position 1:
{
 ^

```

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [February 11, 2022, 12:02am UTC](https://discuss.elastic.co/t/curl-x-put-content-type-application-json-throwing-error/296868/3 "2022-02-11T00:02:27Z")

</div>

I would try copying the command from [Size your shards | Elasticsearch Guide [8.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.0/size-your-shards.html#_this_action_would_add_x_total_shards_but_this_cluster_currently_has_yz_maximum_shards_open) and then pasting it directly into your console and seeing if that works. If it does, then just edit it and change to what you want.

However if you're exceeding this (soft) limit, then you may want to reevaluate your approach.

---

<div class="post-metadata">

### Author: ![byoungman](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@byoungman](https://discuss.elastic.co/u/byoungman)
#### Post date: [February 11, 2022, 2:49pm UTC](https://discuss.elastic.co/t/curl-x-put-content-type-application-json-throwing-error/296868/4 "2022-02-11T14:49:06Z")

</div>

Thanks Mark I'll give this a try and unfortunately I'm constrained in this since my company is not willing to invest any budget for making this stack a proper enterprise level stack so I'm forced to use the basic license on 1 server for everything (Elasticsearch, Kibana, Logstash) for our entire enterprise and we are massively under provisioned here. I'm constantly having to apply band aids to keep the system up.

-Bill

---

<div class="post-metadata">

### Author: ![byoungman](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@byoungman](https://discuss.elastic.co/u/byoungman)
#### Post date: [February 11, 2022, 2:58pm UTC](https://discuss.elastic.co/t/curl-x-put-content-type-application-json-throwing-error/296868/5 "2022-02-11T14:58:13Z")

</div>

Mark,

I did as you suggested and this is the command that I'm running--

```auto
curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
  "persistent" : {
    "cluster.max_shards_per_node": 1200
  }
}
'

```

Error--

```auto
{
  "error" : "Content-Type header [application/x-www-form-urlencoded] is not supp
orted",
  "status" : 406
}

```

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [February 11, 2022, 3:54pm UTC](https://discuss.elastic.co/t/curl-x-put-content-type-application-json-throwing-error/296868/6 "2022-02-11T15:54:12Z")

</div>

Interesting I ran you exact command it is fine.

```auto
hyperion:docker sbrown$ curl -X PUT "localhost:9200/_cluster/settings?pretty" -H 'Content-Type: application/json' -d'
{
  "persistent" : {
    "cluster.max_shards_per_node": 1200
  }
}
'
{
  "acknowledged" : true,
  "persistent" : {
    "cluster" : {
      "max_shards_per_node" : "1200"
    }
  },
  "transient" : { }
}

```

---

<div class="post-metadata">

### Author: ![byoungman](https://avatars.discourse-cdn.com/v4/letter/b/838e76/32.png) [@byoungman](https://discuss.elastic.co/u/byoungman)
#### Post date: [February 11, 2022, 4:24pm UTC](https://discuss.elastic.co/t/curl-x-put-content-type-application-json-throwing-error/296868/7 "2022-02-11T16:24:37Z")

</div>

I should add that our stack is on Windows and I am using the version of curl with mingw

-Bill

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [February 11, 2022, 4:39pm UTC](https://discuss.elastic.co/t/curl-x-put-content-type-application-json-throwing-error/296868/8 "2022-02-11T16:39:02Z")

</div>

Hmmm I Think you are going to need to look close at [the man page](https://curl.se/docs/manpage.html)

Perhaps this section

> --json
> 
> (HTTP) Sends the specified JSON data in a POST request to the HTTP server. --json works as a shortcut for passing on these three options:
> 
> --data [arg] --header "Content-Type: application/json" --header "Accept: application/json"
> 
> There is no verification that the passed in data is actual JSON or that the syntax is correct.
> 
> If you start the data with the letter @, the rest should be a file name to read the data from, or a single dash (-) if you want curl to read the data from stdin. Posting data from a file named 'foobar' would thus be done with [--json](https://curl.se/docs/manpage.html#--json) @foobar and to instead read the data from stdin, use --json @-.
> 
> If this option is used more than once on the same command line, the additional data pieces will be concatenated to the previous before sending.
> 
> The headers this option sets can be overriden with --header as usual.
> 
> Examples:
> 
> curl --json '{ "drink": "coffe" }' [https://example.com](https://example.com) curl --json '{ "drink":' --json ' "coffe" }' [https://example.com](https://example.com) curl --json @prepared [https://example.com](https://example.com) curl --json @- [https://example.com](https://example.com) \< json.txt
> 
> See also [--data-binary](https://curl.se/docs/manpage.html#--data-binary) and [--data-raw](https://curl.se/docs/manpage.html#--data-raw). This option overrides [-F, --form](https://curl.se/docs/manpage.html#-F) and [-I, --head](https://curl.se/docs/manpage.html#-I) and [-T, --upload-file](https://curl.se/docs/manpage.html#-T). Added in 7.82.0.

---

<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: [March 11, 2022, 4:39pm UTC](https://discuss.elastic.co/t/curl-x-put-content-type-application-json-throwing-error/296868/9 "2022-03-11T16:39:52Z")

</div>

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