# Elasticsearch 8.12 Error when tryng to generate a report using curl and an URL given by Discovery tool

**URL:** https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734
**Category:** Elasticsearch
**Created:** [May 4, 2024, 12:48am UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734 "2024-05-04T00:48:49Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![RobertC1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robertc1/32/98051_2.png) [@RobertC1](https://discuss.elastic.co/u/RobertC1)
#### Post date: [May 4, 2024, 12:48am UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/1 "2024-05-04T00:48:49Z")

</div>

Hi guys.  
I am tryng to generate a csv report using the following command

```auto
curl -uelastic:xxxxxx -X POST \
> -H "kbn-xsrf: true" \
        "from": "now-12h"
      },
> -H "Content-Type: application/json" \
  --cacert /etc/kibana/elasticsearch_accusys_com_ar.crt \
> -d '{
> "jobParams": {
> {
> "objectType": "url",
> "relativeUrls": [
> {
> "url": "/app/r",
> "timeRange": {
> "to": "now",
> "from": "now-12h"
> },
> "queryString": "l=DISCOVER_APP_LOCATOR&v=8.12.0&lz=N4IgjgrgpgTgniAXKSsGJCANCANgQwDsBzCfYqJEAa2nhAF8cBnAexgBckBtbkAAQ4BLALZRmHfCIAO2EABNxAYxABdVTiWtcEEYWY8QhVvNZyARvmaUWsllFKFTanEKdQAHlQBMAFgCsAIwA7PIAnPIAtPLyAGa%2Bkb5hYbGRAByx5lF%2Bwd5QAMzyaVAADPhhcm4csABu%2BLhU%2BBAcZjixQrjVMAaI3BoK%2BJIAakJQAO4AkvI%2BASHhUTHxicmpGVmROXmFxWUVOMJiAEpEFEigsTCsIlTGY5GB3gAWci03rGOMODBQF%2BKPE4QunUGsgQMDoEhfCVoSUcNImtYkLF6tYGAwgA%3D"
> }
> ]
> }
> }' \
> --cacert /etc/kibana/elasticsearch_accusys_com_ar.crt \
> "https://elasticsearch.accusys.com.ar:5601/api/reporting/generate/csv"

```

And get the following error

```auto
{"statusCode":400,"error":"Bad Request","message":"Invalid request payload JSON format"}

```

When I try to generate it using Kibana, it freezes.  
Please some help with this issue.  
Thanks in advance.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 4, 2024, 1:18am UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/2 "2024-05-04T01:18:12Z")

</div>

I'm not sure but this looks weird:

```
  -H "kbn-xsrf: true" \
    "from": "now-12h"
  },

```

---

<div class="post-metadata">

### Author: ![RobertC1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robertc1/32/98051_2.png) [@RobertC1](https://discuss.elastic.co/u/RobertC1)
#### Post date: [May 4, 2024, 3:10pm UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/3 "2024-05-04T15:10:27Z")

</div>

Hi [dadoonet](https://discuss.elastic.co/u/dadoonet)  
I changed a little bit the command as you can see

```auto
curl -u administrador:xxxx -X POST \
    -H "Content-Type: application/json" \
    -d '{
      "jobParams": {
        "objectType": "url",
        "timeRange": {
          "from": "2023-09-20"
          "to":" "2023-09-20"
        },
        "queryString": "l=DISCOVER_APP_LOCATOR&v=8.12.0&lz=N4IgjgrgpgTgniAXKSsGJCANCANgQwDsBzCfYqJEAa2nhAF8cBnAexgBckBtbkAAQ4BLALZRmHfCIAO2EABNxAYxABdVTiWtcEEYWY8NIIYUUAPKgCYALAFYAjAHZ5ATnkBaefIBm199ZcXb3cADm8AIw8bR0soAGZ5EKgABnwXORMOWAA3fFwqfAgOVjlvIVwsmANEbiN5fEkANSEoAHcASXkrOydXDy9ff0DgsMj3aNiEpNT0nGExACUiCiRQbxhWEStkyzj3ZJdx5IAVZLjEZOSL5IA6S%2BSALTli7d39w8t7U8tEOKvLu6XJ5MEAwKDrcQAC3ahEquXyyBA8OgSGs92SOGkhWYlEQ3jyOIYDCAA%3D%3D"
      }
    }' \
    --cacert /etc/kibana/elasticsearch_accusys_com_ar.crt \
    "https://elasticsearch.accusys.com.ar:5601/api/reporting/generate/csv"

```

I am searching data in a time range "2024-09-20".  
I made sure that the user "administrador" has permission to generate csv report and the sentence is ommited

```auto
`-H "kbn-xsrf: true" \

```

But, still get the error

```auto
{"statusCode":400,"error":"Bad Request","message":"Invalid request payload JSON format"}

```

Please, another advice?  
Thanks in advance

---

<div class="post-metadata">

### Author: ![RobertC1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robertc1/32/98051_2.png) [@RobertC1](https://discuss.elastic.co/u/RobertC1)
#### Post date: [May 5, 2024, 6:42pm UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/4 "2024-05-05T18:42:17Z")

</div>

Hi guys.  
I solved the issue developing a program with python.  
Thanks any way.

---

<div class="post-metadata">

### Author: ![Sander\_Philipse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sander_philipse/32/101890_2.png) [@Sander\_Philipse](https://discuss.elastic.co/u/Sander_Philipse)
#### Post date: [May 6, 2024, 9:18am UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/5 "2024-05-06T09:18:37Z")

</div>

Hi @RobertC1 I'm glad you solved the problem here. Just FYI: I see a missing comma at the end of the line starting with `"from": "2023-09-20"`, turning this into invalid JSON. This is likely the cause.

---

<div class="post-metadata">

### Author: ![RobertC1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robertc1/32/98051_2.png) [@RobertC1](https://discuss.elastic.co/u/RobertC1)
#### Post date: [May 6, 2024, 2:50pm UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/6 "2024-05-06T14:50:43Z")

</div>

Hi [Sander\_Philipse](https://discuss.elastic.co/u/Sander_Philipse)  
Thanks for your help, nevertheless still get same error.

Any other suggestions would be greatly appreciated.

```auto
curl -u administrador:xxxxxx -X POST \
    -H "Content-Type: application/json" \
    -d '{
      "jobParams": {
        "objectType": "url",
        "timeRange": {
          "from": "2023-09-20",
          "to":" "2023-09-20"
        },
        "queryString": "l=DISCOVER_APP_LOCATOR&v=8.12.0&lz=N4IgjgrgpgTgniAXKSsGJCANCANgQwDsBzCfYqJEAa2nhAF8cBnAexgBckBtbkAAQ4BLALZRmHfCIAO2EABNxAYxABdVTiWtcEEYWY8NIIYUUAPKgCYALAFYAjAHZ5ATnkBaefIBm199ZcXb3cADm8AIw8bR0soAGZ5EKgABnwXORMOWAA3fFwqfAgOVjlvIVwsmANEbiN5fEkANSEoAHcASXkrOydXDy9ff0DgsMj3aNiEpNT0nGExACUiCiRQbxhWEStkyzj3ZJdx5IAVZLjEZOSL5IA6S%2BSALTli7d39w8t7U8tEOKvLu6XJ5MEAwKDrcQAC3ahEquXyyBA8OgSGs92SOGkhWYlEQ3jyOIYDCAA%3D%3D"
      }
    }' \
    --cacert /etc/kibana/elasticsearch_accusys_com_ar.crt \
    "https://elasticsearch.accusys.com.ar:5601/api/reporting/generate/csv"

```

```auto
{"statusCode":400,"error":"Bad Request","message":"Invalid request payload JSON format"}

```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 6, 2024, 3:23pm UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/7 "2024-05-06T15:23:48Z")

</div>

> [@RobertC1](#):
>
> I solved the issue developing a program with python.

Could you share what you did to solve the problem?

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 6, 2024, 3:26pm UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/8 "2024-05-06T15:26:30Z")

</div>

Where did you get this json example from?

From [the documentation](https://www.elastic.co/guide/en/kibana/8.13/automating-report-generation.html#use-a-script), I can see:

```auto
curl \
-XPOST \ 
-u elastic \ 
-H 'kbn-xsrf: true' \ 
'http://0.0.0.0:5601/api/reporting/generate/csv?jobParams=...' 

```

So no json provided here...

---

<div class="post-metadata">

### Author: ![RobertC1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robertc1/32/98051_2.png) [@RobertC1](https://discuss.elastic.co/u/RobertC1)
#### Post date: [May 6, 2024, 6:15pm UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/9 "2024-05-06T18:15:13Z")

</div>

Hi [dadoonet](https://discuss.elastic.co/u/dadoonet)  
Thanks for the advice, and I researched about the format of the command.  
The json command suggested was executed, but with a correction

```auto
curl -XPOST \
-u elastic:xxxx \
-H 'kbn-xsrf: true' \
'http://172.28.194.109:5601/api/reporting/generate/csv?jobParams=https://elasticsearch.accusys.com.ar:5601/app/r?l=DISCOVER_APP_LOCATOR&v=8.12.0&lz=N4IgjgrgpgTgniAXKSsGJAOwPYBNuIAEAOiAAwCMphIANCADYCGmA5hE61EiANbTwQAX3oBnbDAAuSANoyQAAUkBLALZRRkpqoAOdELg0BjEAF1T9I9gYRVmUbKx5s%2B0XvoAjJqO4WQyzEMADx4AdiMPCIBWAE4yAFpQgDMADgA2eIoKKCN4jyyPeKTcACYyAGZyqCSyD1DuegDJWAA3JgYeAAt9JOUGZpgHRBk%2FXCYtADVlKAB3AElcMIjouMTUjKycvIKi0oqqmrqGkBV1ACUWLiRQJJhsVR4ykvL4shjXqIAVCjJEMl%2F%2FgA6f5kABa%2BkkLgwTxebw%2B3wofwBZGB%2F3BIhAMGqWNEnTmmAGbQ6yBAROgSDKIPoOiYEB8SEkMGgQiEQA'

```

And get the following error

```auto
curl: (52) Empty reply from server

```

Please, any advice?

About your question "Where did you get this json example from?", doing a research job.  
Thanks

---

<div class="post-metadata">

### Author: ![RobertC1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robertc1/32/98051_2.png) [@RobertC1](https://discuss.elastic.co/u/RobertC1)
#### Post date: [May 6, 2024, 6:29pm UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/10 "2024-05-06T18:29:24Z")

</div>

Hi [dadoonet](https://discuss.elastic.co/u/dadoonet)

The python

```auto
from elasticsearch import Elasticsearch
from datetime import datetime

# Elasticsearch URL
ELASTICSEARCH_URL = "http://localhost:9200"

# Elasticsearch username and password
USERNAME = "elastic"
PASSWORD = "xxxx"

# Create Elasticsearch client with basic authentication
es = Elasticsearch([ELASTICSEARCH_URL], basic_auth=(USERNAME, PASSWORD))
# Get the current date and time

# Check if the connection is successful
if not es.ping():
    print("Could not connect to Elasticsearch")
    exit()

start_date = "2023-09-05T00:00:00"
end_date = "2023-09-05T23:59:59"
# Define the date range
# Initial search query with date range
query = {
    "size": 10000, # Number of documents to retrieve per scroll
    "query": {
        "bool": {
            "must": [
                {
                    "range": {
                        "@timestamp": {
                            "gte": start_date,
                            "lte": end_date
                        }
                    }
                }
            ]
        }
    },
    "sort": [
        {"nodo": {"order": "asc"}}
    ]
}
# Execute initial search request with scroll
response = es.search(index="trx_hours_history", body=query, scroll="1s")

# Store unique document identifiers to avoid duplicates
seen_ids = set()

#print(f'{fecha},"{nodo_str}",{base},{sp},{segundo_div:.4f},"{cant_format}"')
# Process initial search response
scroll_id = response["_scroll_id"]
hits = response["hits"]["hits"]
total_hits = response["hits"]["total"]["value"]

# Process the first batch of results
for hit in hits:
    source = hit["_source"]
    doc_id = hit["_id"] # Get document ID
    # Check if the document ID has been seen before
    if doc_id not in seen_ids:
        seen_ids.add(doc_id)
        fecha = source.get("@timestamp")
        nodo = source.get("nodo")
        nodo_str = str(nodo).zfill(2)
        base = source.get("base")
        sp = source.get("sp")
        cant_trn = source.get("cant_trn")
        cant_format = "{:,}".format(cant_trn)
        segundo_prom = source.get("segundo_prom")
        if segundo_prom is not None:
            segundo_div = segundo_prom / 1000
        print(f'{fecha},"{nodo_str}",{base},{sp},{segundo_div:.4f},"{cant_format}"')

```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 6, 2024, 11:25pm UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/11 "2024-05-06T23:25:26Z")

</div>

Thanks for sharing your code. I think it could be super useful for the community. If you don't mind, I'd mark it as a solution for your post so people can get inspiration from it.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [May 6, 2024, 11:26pm UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/12 "2024-05-06T23:26:53Z")

</div>

> [@RobertC1](#):
>
> About your question "Where did you get this json example from?", doing a research job.

Do you remember which page did you find?

---

<div class="post-metadata">

### Author: ![RobertC1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robertc1/32/98051_2.png) [@RobertC1](https://discuss.elastic.co/u/RobertC1)
#### Post date: [May 7, 2024, 12:17am UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/13 "2024-05-07T00:17:19Z")

</div>

[dadoonet](https://discuss.elastic.co/u/dadoonet)

Thanks for your words and I am really glad to help the community.  
Best regards.

---

<div class="post-metadata">

### Author: ![RobertC1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robertc1/32/98051_2.png) [@RobertC1](https://discuss.elastic.co/u/RobertC1)
#### Post date: [May 7, 2024, 12:42am UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/14 "2024-05-07T00:42:32Z")

</div>

[dadoonet](https://discuss.elastic.co/u/dadoonet)  
I don't really remember, I believe it was a mix of a youtube video and chatgpt.  
It was sunday and late and when I found the python solution, I didn't insist with the curl command.  
Best Regards.

---

<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: [June 4, 2024, 12:43am UTC](https://discuss.elastic.co/t/elasticsearch-8-12-error-when-tryng-to-generate-a-report-using-curl-and-an-url-given-by-discovery-tool/358734/15 "2024-06-04T00:43:22Z")

</div>

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