# Kibana API for automatic Export all

**URL:** https://discuss.elastic.co/t/kibana-api-for-automatic-export-all/201243
**Category:** Kibana
**Created:** [September 26, 2019, 1:32pm UTC](https://discuss.elastic.co/t/kibana-api-for-automatic-export-all/201243 "2019-09-26T13:32:31Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![GitsBdr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gitsbdr/32/58828_2.png) [@GitsBdr](https://discuss.elastic.co/u/GitsBdr)
#### Post date: [September 26, 2019, 1:32pm UTC](https://discuss.elastic.co/t/kibana-api-for-automatic-export-all/201243/1 "2019-09-26T13:32:31Z")

</div>

Hi all,

Thanks in advance for your time,

I'm trying to develop a shell script to automatize backups of my Kibana saved objects (dashboards+all related objects)

Running :  
`curl -k -XGET 'https://xx.xx.xx.x:5601/api/kibana/dashboards/export?dashboard=5017f0b0-28a2-11e9-bc68-e1bf949a2fb9' -H 'kbn-xsrf: true' -H 'Content-Type: application/json'`  
works well and returns my dashboard attributes + visu and index-pattern linked with

I'm now trying to find a way to export all my saved objects and not only one.  
Isn't there an easier way to do it than first get all different dashboard ids and export them one by one ?

Thanks  
Guillaume

---

<div class="post-metadata">

### Author: ![mikecote](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikecote/32/58549_2.png) [@mikecote](https://discuss.elastic.co/u/mikecote)
#### Post date: [September 26, 2019, 3:38pm UTC](https://discuss.elastic.co/t/kibana-api-for-automatic-export-all/201243/2 "2019-09-26T15:38:09Z")

</div>

Hi @GitsBdr,

As of Kibana 7.1 you can use the new export API to do the same thing: [https://www.elastic.co/guide/en/kibana/current/saved-objects-api-export.html](https://www.elastic.co/guide/en/kibana/current/saved-objects-api-export.html). There is also a `includeReferencesDeep` flag you can set to true if you want all dependent objects to be exported as well.

This will give you a `.ndjson` file that you can later on pass to the import API: [https://www.elastic.co/guide/en/kibana/7.2/saved-objects-api-import.html](https://www.elastic.co/guide/en/kibana/7.2/saved-objects-api-import.html).

The export API is limited to certain types of saved objects but can handle dashboards, visualizations, saved search, index patterns. You should be able to pass `type: ['dashboard']` and `includeReferencesDeep: true` to have all your dashboards with dependent objects exported.

Hope this helps,  
Mike.

---

<div class="post-metadata">

### Author: ![GitsBdr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gitsbdr/32/58828_2.png) [@GitsBdr](https://discuss.elastic.co/u/GitsBdr)
#### Post date: [September 30, 2019, 11:10am UTC](https://discuss.elastic.co/t/kibana-api-for-automatic-export-all/201243/3 "2019-09-30T11:10:01Z")

</div>

Hi @mikecote and thanks for your help here

I started by checking this doc too but it has never worked for me and I couldn't figure out why ...

```
curl -k -X POST "https://myIP:5601/api/saved_objects/_export" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
{
   "type": "dashboard"
}
'

```

`{"statusCode":400,"error":"Bad Request","message":"child \"attributes\" fails because [\"attributes\" is required]. \"type\" is not allowed","validation":{"source":"payload","keys":["attributes","type"]}}`

So I tried :

```
curl -k -X POST "https://myIP:5601/api/saved_objects/_export" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
{
   "attributes": { "type": "dashboard" }
}
'

```

`{"message":"Unsupported saved object type: '_export': Bad Request","statusCode":400,"error":"Bad Request"}`

---

<div class="post-metadata">

### Author: ![mikecote](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikecote/32/58549_2.png) [@mikecote](https://discuss.elastic.co/u/mikecote)
#### Post date: [September 30, 2019, 12:56pm UTC](https://discuss.elastic.co/t/kibana-api-for-automatic-export-all/201243/4 "2019-09-30T12:56:48Z")

</div>

Hi @GitsBdr,

Sorry I gave the wrong Kibana version that the feature got delivered in. I was thinking it was 7.1 but it's actually 7.2. I was able to reproduce your issue on 7.1 and get the same error message. I cross checked the pull requests to confirm and that is the case (only as of 7.2 the new APIs are in place).

I'm assuming you are running on a version \< 7.2?

Hope this helps,  
Mike.

---

<div class="post-metadata">

### Author: ![GitsBdr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gitsbdr/32/58828_2.png) [@GitsBdr](https://discuss.elastic.co/u/GitsBdr)
#### Post date: [September 30, 2019, 1:06pm UTC](https://discuss.elastic.co/t/kibana-api-for-automatic-export-all/201243/5 "2019-09-30T13:06:02Z")

</div>

Hi,

No worries !  
I confirm this is working with kibana-7.3 and not kibana-7.1 (got both installed)  
Thank you very much !

[edit]  
However,  
adding includeReferencesDeep, doesn't seem to work though :

```
curl -k -X POST "https://myIP:5601/api/saved_objects/_export" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d'
{
 "type": "dashboard",
 "includeReferencesDeep": "true"
}
'

```

`{"statusCode":400,"error":"Bad Request","message":"Bad Request","attributes":{"objects":[{"id":"AWM_MwmMTOMwvg7W1USl","type":"index-pattern","error":{"statusCode":404,"message":"Not found"}}]}}`

---

<div class="post-metadata">

### Author: ![mikecote](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mikecote/32/58549_2.png) [@mikecote](https://discuss.elastic.co/u/mikecote)
#### Post date: [September 30, 2019, 1:41pm UTC](https://discuss.elastic.co/t/kibana-api-for-automatic-export-all/201243/6 "2019-09-30T13:41:39Z")

</div>

Hi @GitsBdr,

I think you're hitting the proper API now. The error message you're receiving I believe is because the system can't find the index pattern with id `AWM_MwmMTOMwvg7W1USl`. Something down the chain must have a broken reference to an index pattern and is failing to export (saved search or visualization possibly).

We have an issue open ([https://github.com/elastic/kibana/issues/43876](https://github.com/elastic/kibana/issues/43876)) to allow the export to go through with missing references but at this time the bad reference would have to be fixed before the export is successful.

To find which object is using the missing index pattern, you can use the `find` API ([https://www.elastic.co/guide/en/kibana/current/saved-objects-api-find.html](https://www.elastic.co/guide/en/kibana/current/saved-objects-api-find.html)) with `hasReference` parameter. `hasReference: { type: 'index-pattern', id: 'AWM_MwmMTOMwvg7W1USl' }`. Depending on the results, you may be able to fix it in the Saved Objects Management section.

Hope this helps,  
Mike.

---

<div class="post-metadata">

### Author: ![GitsBdr](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gitsbdr/32/58828_2.png) [@GitsBdr](https://discuss.elastic.co/u/GitsBdr)
#### Post date: [September 30, 2019, 1:46pm UTC](https://discuss.elastic.co/t/kibana-api-for-automatic-export-all/201243/7 "2019-09-30T13:46:36Z")

</div>

Lovely !

I'm sure it will help - was able to make it work without `"includeReferencesDeep": "true"` anyway  
Something on my side now  
Thanks again for your appreciated help  
And yes, issue #43876 would be a great improvement with warnings at the end of the process saying what went wrong 🙂

Guillaume

---

<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: [October 28, 2019, 1:46pm UTC](https://discuss.elastic.co/t/kibana-api-for-automatic-export-all/201243/8 "2019-10-28T13:46:46Z")

</div>

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