# Export Rules -- Getting BAD request

**URL:** https://discuss.elastic.co/t/export-rules-getting-bad-request/296101
**Category:** Kibana
**Tags:** detection-rules
**Created:** [February 2, 2022, 5:13pm UTC](https://discuss.elastic.co/t/export-rules-getting-bad-request/296101 "2022-02-02T17:13:28Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Detlef](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/detlef/32/38723_2.png) [@Detlef](https://discuss.elastic.co/u/Detlef)
#### Post date: [February 2, 2022, 5:13pm UTC](https://discuss.elastic.co/t/export-rules-getting-bad-request/296101/1 "2022-02-02T17:13:28Z")

</div>

I'm trying to extract my created detection rules.

From my python script I receive the following debug messages:

```auto
2022-02-02 17:57:22,859 __main__ INFO Selected the following elastic host for requests: dw-prodkib-00.mydom.country
2022-02-02 17:57:22,859 __main__ DEBUG Executing POST request against Kibana with http://dw-prodkib-00.mydom.country:5601/api/detection_engine/rules/_export?file_name=/tmp/exportedRulesProduction.ndjson
2022-02-02 17:57:22,859 __main__ DEBUG elasticRequest.auth=('elastic', 'TopSecretPassword')
2022-02-02 17:57:22,859 __main__ DEBUG elasticRequest.headers={'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}
2022-02-02 17:57:22,860 urllib3.connectionpool DEBUG Starting new HTTP connection (1): dw-prodkib-00.mydom.country:5601
2022-02-02 17:57:22,914 urllib3.connectionpool DEBUG http://dw-prodkib-00.mydom.country:5601 "POST /api/detection_engine/rules/_export?file_name=/tmp/exportedRulesProduction.ndjson HTTP/1.1" 400 92
2022-02-02 17:57:22,915 __main__ ERROR An Http Error occurred:HTTPError('400 Client Error: Bad Request for url: http://dw-prodkib-00.mydom.country:5601/api/detection_engine/rules/_export?file_name=/tmp/exportedRulesProduction.ndjson')
2022-02-02 17:57:22,916 __main__ ERROR An exception occurred while processing export rules request

```

I already tried without any parameter, but the error remains the same.

---

<div class="post-metadata">

### Author: ![jamesspi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jamesspi/32/24479_2.png) [@jamesspi](https://discuss.elastic.co/u/jamesspi)
#### Post date: [February 3, 2022, 10:42am UTC](https://discuss.elastic.co/t/export-rules-getting-bad-request/296101/2 "2022-02-03T10:42:01Z")

</div>

> [@Detlef](#):
>
> `2022-02-02 17:57:22,859 __main__ DEBUG elasticRequest.headers={'content-type': 'application/json', 'Accept-Charset': 'UTF-8'}`

Hi @Detlef , as I mentioned on the community slack, it looks like you haven't added a `kbn-xsrf` header, which is needed for any API call to Kibana.

---

<div class="post-metadata">

### Author: ![Detlef](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/detlef/32/38723_2.png) [@Detlef](https://discuss.elastic.co/u/Detlef)
#### Post date: [February 3, 2022, 10:56am UTC](https://discuss.elastic.co/t/export-rules-getting-bad-request/296101/3 "2022-02-03T10:56:05Z")

</div>

That was the trick.

```auto
2022-02-03 11:50:10,513 __main__ INFO Selected the following elastic host for requests: dw-prodkib-00.<my
2022-02-03 11:50:10,513 __main__ DEBUG Executing POST request against Kibana with http://dw-prodkib-00.mydom.country:5601/api/detection_engine/rules/_export?file_name=/tmp/exportedRulesProduction.ndjson
2022-02-03 11:50:10,513 __main__ DEBUG kibanaRequest.auth=('elastic', 'TopSecretPassword')
2022-02-03 11:50:10,513 __main__ DEBUG kibanaRequest.headers={'content-type': 'application/json', 'Accept-Charset': 'UTF-8', 'kbn-xsrf': 'true'}
2022-02-03 11:50:10,515 urllib3.connectionpool DEBUG Starting new HTTP connection (1): dw-prodkib-00.mydom.country:5601
2022-02-03 11:50:12,115 urllib3.connectionpool DEBUG http://dw-prodkib-00.mydom.country:5601 "POST /api/detection_engine/rules/_export?file_name=/tmp/exportedRulesProduction.ndjson HTTP/1.1" 200 297
2022-02-03 11:50:12,117 __main__ INFO Rules have been exported successfully
2022-02-03 11:50:12,118 __main__ INFO to file /tmp/exportedRulesProduction.ndjson

```

Thanks to @jamesspi

---

<div class="post-metadata">

### Author: ![jamesspi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jamesspi/32/24479_2.png) [@jamesspi](https://discuss.elastic.co/u/jamesspi)
#### Post date: [February 3, 2022, 12:09pm UTC](https://discuss.elastic.co/t/export-rules-getting-bad-request/296101/4 "2022-02-03T12:09:50Z")

</div>

Great!

---

<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 3, 2022, 12:10pm UTC](https://discuss.elastic.co/t/export-rules-getting-bad-request/296101/5 "2022-03-03T12:10:38Z")

</div>

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