# Automating export from Elastic Cloud

**URL:** https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045
**Category:** Kibana
**Created:** [April 1, 2020, 12:27pm UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045 "2020-04-01T12:27:11Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![t3fsx](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@t3fsx](https://discuss.elastic.co/u/t3fsx)
#### Post date: [April 1, 2020, 12:27pm UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/1 "2020-04-01T12:27:11Z")

</div>

Hi,

I read this thread ([Kibana API for automatic Export all](https://discuss.elastic.co/t/kibana-api-for-automatic-export-all/201243/3)) which is attempting to do something very similar to what I'm trying and the information in it is valuable.

That being said, I'm not entirely sure how to apply what is discussed there to Elastic Cloud, which is where my cluster is running.

I was wondering if someone had automated the export of searches, views and dashboards from Elastic Cloud through a "backup script" of some sort.

Thank you!

---

<div class="post-metadata">

### Author: ![LizaD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lizad/32/51074_2.png) [@LizaD](https://discuss.elastic.co/u/LizaD)
#### Post date: [April 1, 2020, 10:03pm UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/2 "2020-04-01T22:03:45Z")

</div>

Hi @t3fsx,

You can use the Kibana API on Cloud instance the same, just plugin the Kibana Cloud URL and your credentials to authenticate the request.  
Hope this helps.

Thanks,  
Liza

---

<div class="post-metadata">

### Author: ![t3fsx](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@t3fsx](https://discuss.elastic.co/u/t3fsx)
#### Post date: [April 2, 2020, 2:14am UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/3 "2020-04-02T02:14:48Z")

</div>

Hi @LizaD

Thanks for the reply. I'm not entirely sure how I would go about getting the credentials. What kind of credentials would I be able to utilize via curl?

Also, the documentation doesn't, as far as I was able to tell, list the possible objects that can be exported: [https://www.elastic.co/guide/en/kibana/master/saved-objects-api-export.html](https://www.elastic.co/guide/en/kibana/master/saved-objects-api-export.html)

`index-pattern`, `dashboard` and `visualisation` are referenced. I assume `search` is supported as well?

---

<div class="post-metadata">

### Author: ![LizaD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lizad/32/51074_2.png) [@LizaD](https://discuss.elastic.co/u/LizaD)
#### Post date: [April 2, 2020, 3:13pm UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/4 "2020-04-02T15:13:48Z")

</div>

Hi @t3fsx,

For curl you can use -u user:password option and the credentials would be same as you login into UI.

[https://www.elastic.co/guide/en/kibana/master/saved-objects-api-get.html](https://www.elastic.co/guide/en/kibana/master/saved-objects-api-get.html), shows search as a valid type.

Thanks,  
Liza

---

<div class="post-metadata">

### Author: ![t3fsx](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@t3fsx](https://discuss.elastic.co/u/t3fsx)
#### Post date: [April 2, 2020, 6:10pm UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/5 "2020-04-02T18:10:50Z")

</div>

> [@LizaD](#):
>
> [Get object API | Kibana Guide [master] | Elastic](https://www.elastic.co/guide/en/kibana/master/saved-objects-api-get.html)

Hey @LizaD, thank you!

I'm much closer, even though still not there 😅

I'm using:

`curl -X POST -H "kbn-xsrf: script" -u "$kCreds" --data '{"type":"search","id":"a02fd230-72bf-11ea-97e5-156620cf9598"}' $kURL/$kPATH`

However I keep getting the following error:

`{"statusCode":400,"error":"Bad Request","message":"child \"id\" fails because [\"id\" is not allowed to be empty]","validation":{"source":"params","keys":["id"]}}%`

I've tried escaping the request `(--data)` in all ways I knew how.

I was hoping `bulk` would allow me to export all objects by `type` (without having to specify the ID) but that doesn't seem to be possible.

---

<div class="post-metadata">

### Author: ![LizaD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lizad/32/51074_2.png) [@LizaD](https://discuss.elastic.co/u/LizaD)
#### Post date: [April 2, 2020, 6:37pm UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/6 "2020-04-02T18:37:51Z")

</div>

Nice @t3fsx, it is getting closer :).

I think you are just missing the objects key in your data, see:

```auto
-d'
{ 
  "objects": [
   {
    "type": "search", 
    "id": "<yourid>"
   }
 ]
}

```

Give it a try and let me know, thanks!

---

<div class="post-metadata">

### Author: ![t3fsx](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@t3fsx](https://discuss.elastic.co/u/t3fsx)
#### Post date: [April 2, 2020, 7:29pm UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/7 "2020-04-02T19:29:29Z")

</div>

> [@t3fsx](#):
>
> [Export objects API | Kibana Guide [master] | Elastic](https://www.elastic.co/guide/en/kibana/master/saved-objects-api-export.html)

Hi again @LizaD! Thank you so much for your help.

I was actually trying to use the \_bulk\_get API but have since changed to the one you mentioned to better follow up with the recommendations you are giving.

I'm now passing everything as per the documentation:

 ![Screenshot 2020-04-02 at 20.28.51](https://us1.discourse-cdn.com/elastic/original/3X/5/f/5f79f4b6a96c1450552d2f009854c99ae9454abd.png)

Any tips? Thank you for all your help!

---

<div class="post-metadata">

### Author: ![LizaD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lizad/32/51074_2.png) [@LizaD](https://discuss.elastic.co/u/LizaD)
#### Post date: [April 2, 2020, 9:13pm UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/8 "2020-04-02T21:13:00Z")

</div>

Hi @t3fsx,

You need to add this to the header of the curl command, it should resolve this error.

```auto
-H 'Content-Type: application/json'

```

Thanks,  
Liza

---

<div class="post-metadata">

### Author: ![t3fsx](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@t3fsx](https://discuss.elastic.co/u/t3fsx)
#### Post date: [April 3, 2020, 12:09am UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/9 "2020-04-03T00:09:17Z")

</div>

Hey again @LizaD,

Thank you for your perseverance in this. 🤗

I had that before and eventually moved to what I posted on the post before the error. Basically, if you use what you mentioned, you'll get:

`{"statusCode":400,"error":"Bad Request","message":"Request must contain a kbn-xsrf header."}%``

That's what I'm using `-H "kbn-xsrf: script"` even though putting anything in front of `kbn-xsrf:` will get rid of that error. Saw that being recommended here: [Request must contain a kbn-xsrf header](https://discuss.elastic.co/t/request-must-contain-a-kbn-xsrf-header/96736)

---

<div class="post-metadata">

### Author: ![LizaD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lizad/32/51074_2.png) [@LizaD](https://discuss.elastic.co/u/LizaD)
#### Post date: [April 3, 2020, 2:23am UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/10 "2020-04-03T02:23:24Z")

</div>

Thanks @t3fsx let's try both 🙂

```auto
-H 'kbn-xsrf: true' -H 'Content-Type: application/json'

```

Let me know.

---

<div class="post-metadata">

### Author: ![t3fsx](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@t3fsx](https://discuss.elastic.co/u/t3fsx)
#### Post date: [April 3, 2020, 11:44am UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/11 "2020-04-03T11:44:29Z")

</div>

Worthy of 🎇! It works! 🕶 Thank you very much @LizaD! It's was actually my bad as the "copy as curl" link in the documentation actually creates the curl command identical to what we have here.

To make it easier for someone that might end up here, the full command:

```auto
curl -X POST -H "kbn-xsrf: script" -H "Content-Type: application/json" -u elastic:pass https://yourID.eu-central-1.aws.cloud.es.io:9243/api/saved_objects/_export -d '{
  "objects": [
   {
    "type": "search",
    "id": "a02fd230-72bf-11ea-97e5-156620cf9598"
   }
 ]
}' -o test.json

```

Another question, and this might be something for another threat, is related to the IDs. I always assumed that (and the documentation provides an example of this), similar to the web UX, I could specify a type and download all saved objects of that type.

However, using `api/saved_objects/_export` specifying an ID id required. Is there an endpoint that would allow exporting all from type?

---

<div class="post-metadata">

### Author: ![t3fsx](https://avatars.discourse-cdn.com/v4/letter/t/bc79bd/32.png) [@t3fsx](https://discuss.elastic.co/u/t3fsx)
#### Post date: [April 4, 2020, 12:40am UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/12 "2020-04-04T00:40:50Z")

</div>

The `objects` was the part that was interfering with downloading all object types at once. As per the documentation it should not be included.

Thank you @LizaD for all your help!

---

<div class="post-metadata">

### Author: ![LizaD](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lizad/32/51074_2.png) [@LizaD](https://discuss.elastic.co/u/LizaD)
#### Post date: [April 6, 2020, 6:36pm UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/13 "2020-04-06T18:36:10Z")

</div>

Yay @t3fsx! Glad you got it all working 🙂 !

---

<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: [May 4, 2020, 6:36pm UTC](https://discuss.elastic.co/t/automating-export-from-elastic-cloud/226045/14 "2020-05-04T18:36:14Z")

</div>

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