# Curl'ing Kibana Dashboards exported into NDJSON

**URL:** <https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012>\
**Category:** Kibana\
**Created:** [February 8, 2023, 11:44am UTC](https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012 "2023-02-08T11:44:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![plissken](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@plissken](https://discuss.elastic.co/u/plissken)\
**Post date:** [February 8, 2023, 11:44am UTC](https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012/1 "2023-02-08T11:44:31Z")

</div>

I'm having considerable difficulty in understanding the documentation on the Kibana API's. There's so much out of date information on the web that I could literally spend months doing syntax jenga. I have a set of dashboards and visualisations exported from the kibana dashboard into an ndjson file. I'm trying to curl this file back into production systems via the kibana dashboards/import API. My base command looks like this ...

curl -k -XPOST -H 'kbn-xsrf: true' [http://127.0.0.1:5601/s/test/api/kibana/dashboards/import](http://127.0.0.1:5601/s/test/api/kibana/dashboards/import) -d @dashboardfile.ndjson

I've tried several syntax changes, which always result in errors. Currently getting a 404  
"error":"Bad Request","message":"[request body.objects]: expected value of type [array] but got [undefined]"}

Could someone kindly assist before I'm escorted into a padded cell? Thank you in advance.

---

<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 8, 2023, 2:48pm UTC](https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012/2 "2023-02-08T14:48:22Z")

</div>

What version are you on?

I assume you actually have a space named `test`

I Recommend sticking with our documentation.

Tell me the version and I will test

Assuming you are using a fairly new version you should use the Saved Objects API

> **[Saved objects APIs | Kibana Guide \[8.6\] | Elastic](https://www.elastic.co/guide/en/kibana/current/saved-objects-api.html)**
>
> Conceptual and step-by-step procedures for using runtime fields, scripted fields, and field formatters.

I suspect your error is that your ndjson is malformed it needs to be an array so curious how did you create / download the `dashboardfile.ndjson`

---

<div class="post-metadata">

**Author:** ![plissken](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@plissken](https://discuss.elastic.co/u/plissken)\
**Post date:** [February 8, 2023, 9:39pm UTC](https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012/3 "2023-02-08T21:39:44Z")

</div>

Hi Stephen. I'm on 8.5.0. The ndjson file was created by Kibana on the export saved objects menu. So I went into the kibana UI, navigated to Kibana-\>Saved Objects-\> and exported the selected dashboard. Included all objects associated with the dashboard. Haven't touched the ndjson file, so trying to curl it as downloaded. I did try some permutations of curl for saved objects API but couldn't get that working either. Thanks.

---

<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 8, 2023, 9:56pm UTC](https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012/4 "2023-02-08T21:56:20Z")

</div>

> [@plissken](#):
>
> So I went into the kibana UI, navigated to Kibana-\>Saved Objects-\> and exported the selected dashboard. Included all objects associated with the dashboard. Haven't touched the ndjson file, so trying to curl it as downloaded. I

Pretty sure you should then be using the saved object API not the dashboard API to reload.

You are mixing UI and APIs.

I will check a little later if I can

---

<div class="post-metadata">

**Author:** ![plissken](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@plissken](https://discuss.elastic.co/u/plissken)\
**Post date:** [February 9, 2023, 8:09am UTC](https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012/5 "2023-02-09T08:09:43Z")

</div>

Thanks Stephen. I also missed getting back to you about the space "test". Yes, it's been created and ready for dashboards.

---

<div class="post-metadata">

**Author:** ![plissken](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@plissken](https://discuss.elastic.co/u/plissken)\
**Post date:** [February 10, 2023, 2:11pm UTC](https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012/6 "2023-02-10T14:11:06Z")

</div>

Hi Stephen. Similar issues using the saved objects API. I've tried the following:

curl -k -XPOST -H 'kbn-xsrf: true' -H 'Content-Type: application/json'  
[http://127.0.0.1:5601/s/test/api/saved\_objects/\_bulk\_create](http://127.0.0.1:5601/s/test/api/saved_objects/_bulk_create) -d @app-server-system-overview.ndjso

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

and trying x-ndjson (thinking it may explain the error)

{"statusCode":415,"error":"Unsupported Media Type","message":"Unsupported Media Type"}

And then avoiding the bulk API in favour of saved objects/dashboards

curl -k -XPOST -H 'kbn-xsrf: true' -H 'Content-Type: application/json'  
[http://127.0.0.1:5601/s/test/api/saved\_objects/dashboard](http://127.0.0.1:5601/s/test/api/saved_objects/dashboard) -d @app-server-system-overview.ndjson

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

There must be something wrong with the ndjson file. Perhaps I need to pre-format it before importing it. But as it comes directly from the Kibana UI export I didn't think this was necessary. Extract of app-server-system-overview.ndjson as follows:

{"attributes":{"description":"","kibanaSavedObjectMeta":{"searchSourceJSON":"{"query":{"query":"","language":"kuery"},"filter":}"},"title":"CPU Usage [Metricbeat System] ECS","uiStateJSON":"{}","version":1,"visState":"{"title":"CPU Usage [Metricbeat System] ECS","type":"metrics","aggs":,"params":{"time\_range\_mode":"entire\_time\_range","axis\_formatter":"number","axis\_position":"left","id":"80a04950-1b19-11e7-b09e-037021c4f8df","index\_pattern":"metricbeat-\*","interval":"auto","series":[{"time\_range\_mode":"entire\_time\_range","axis\_position":"right","chart\_type":"line","color":"#68BC00","fill":"1","formatter":"percent","id":"80a04951-1b19-11e7-b09e-037021c4f8df","label":"user","line\_width":1,"metrics":[{"field":"system.cpu.user.pct","id":"80a04952-1b19-11e7-b09e-037021c4f8df","type":"avg"}],"point\_size":"0","seperate\_axis":0,"split\_color\_mode":"gradient","split\_mode":"everything","stacked":"stacked"},{"time\_range\_mode":"entire\_time\_range","axis\_position":"right","chart\_type":"line","color":"rgba(211,49,21,1)","fill":"1","formatter":"percent","id":"993acf30-1b19-11e7-b09e-037021c4f8df","label":"system","line\_width":1,"metrics":[{"field":"system.cpu.system.pct","id":"993acf31-1b19-11e7-b09e-037021c4f8df","type":"avg"}],"point\_size":"0","seperate\_axis":0,"split\_color\_mode":"gradient","split\_mode":"everything","stacked":"stacked"},{"time\_range\_mode":"entire\_time\_range","axis\_position":"right","chart\_type":"line","color":"rgba(123,100,255,1)","fill":"1","formatter":"percent","id":"65ca35e0-1b1a-11e7-b09e-037021c4f8df","label":"nice","line\_width":1,"metrics":[{"field":"system.cpu.nice.pct","id":"65ca5cf0-1b1a-11e7-b09e-037021c4f8df","type":"avg"}],"point\_size":"0","seperate\_axis":0,"split\_color\_mode":"gradient","split\_mode":"everything","stacked":"stacked"},{"time\_range\_mode":"entire\_time\_range","axis\_position":"right","chart\_type":"line","color":"rgba(226,115,0,1)","fill":"1","formatter":"percent","id":"741b5f20-1b1a-11e7-b09e-037021c4f8df","label":"irq","line\_width":1,"metrics":[{"field":"system.cpu.irq.pct","id":"741b5f21-1b1a-11e7-b09e-037021c4f8df","type":"avg"}],"point\_size":"0","seperate\_axis":0,"split\_color\_mode":"gradient","split\_mode":"everything","stacked":"stacked"},{"time\_range\_mode":"entire\_time\_range","axis\_position":"right","chart\_type":"line","color":"rgba(176,188,0,1)","fill":"1","formatter":"percent","id":"2efc5d40-1b1a-11e7-b09e-037021c4f8df","label":"softirq","line\_width":1,"metrics":[{"field":"system.cpu.softirq.pct","id":"2efc5d41-1b1a-11e7-b09e-037021c4f8df","type":"avg"}],"point\_size":"0","seperate\_axis":0,"split\_color\_mode":"gradient","split\_mode":"everything","stacked":"stacked"},{"time\_range\_mode":"entire\_time\_range","axis\_position":"right","chart\_type":"line","color":"rgba(15,20,25,1)","fill":"1","formatter":"percent","id":"ae644a30-1b19-11e7-b09e-037021c4f8df","label":"iowait","line\_width":1,"metrics":[{"field":"system.cpu.iowait.pct","id":"ae644a31-1b19-11e7-b09e-037021c4f8df","type":"avg"}],"point\_size":"0","seperate\_axis":0,"split\_color\_mode":"gradient","split\_mode":"everything","stacked":"stacked"}],"show\_grid":1,"show\_legend":1,"time\_field":"@timestamp","type":"timeseries","use\_kibana\_indexes":false,"drop\_last\_bucket":1,"axis\_scale":"normal","truncate\_legend":1,"max\_lines\_legend":1,"tooltip\_mode":"show\_all","isModelInvalid":false,"filter":{"query":"host.name:\"metricbeat-pri\"","language":"kuery"}}}"},"coreMigrationVersion":"8.5.0","id":"79e5b8fd-704b-4e00-a38f-6f35e6914773","migrationVersion":{"visualization":"8.5.0"},"references":,"type":"visualization","updated\_at":"2023-02-08T08:24:33.365Z","version":"Wzk1MDEsM10="}  
{"attributes"

---

<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 10, 2023, 4:34pm UTC](https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012/7 "2023-02-10T16:34:22Z")

</div>

Ok @plissken

Here is what I have for you now... and Wow that seemed a bit harder than I thought ...

So this is for an individual I used `_export` and `_import` ... I have not tried `_bulk` yet

So first I list to find the Object I am after in my initial / default space

```auto
# Get Dashboards
curl -X GET -H 'Content-Type: application/json' -H 'kbn-xsrf: true' http://localhost:5601/api/saved_objects/_find?type=dashboard | jq

```

In this case is is the eCommerce Dashboard

```auto
    {
      "type": "dashboard",
      "id": "722b74f0-b882-11e8-a6d9-e546fe2bba5f",

```

So now I `_export` it ... it takes both the `type` and `id` as far as I can tell in the `objects` array

```auto
# Export the actual Dashboard
curl -X POST -H 'Content-Type: application/json' -H 'kbn-xsrf: true' http://localhost:5601/api/saved_objects/_export -d '{"objects":[{"type":"dashboard","id":"722b74f0-b882-11e8-a6d9-e546fe2bba5f"}]}' > saved-dashboard.ndjson

```

Now `_import` to another space look at the syntax careful

```auto
# Import to a new space
curl -X POST -H 'kbn-xsrf: true' http://localhost:5601/s/test/api/saved_objects/_import?createNewCopies=true --form file=@saved-dashboard.ndjson
{"successCount":1,"success":true,"warnings":[],"successResults":[{"type":"dashboard","id":"722b74f0-b882-11e8-a6d9-e546fe2bba5f","meta":{"title":"[eCommerce] Revenue Dashboard","icon":"dashboardApp"},"destinationId":"e410188d-e9fd-40cc-bdc9-aa307d0a7165"}]}

```

And my Pretty new dashboard in my space `test`

 ![Screen Shot 2023-02-10 at 8.33.48 AM](https://us1.discourse-cdn.com/elastic/original/3X/9/a/9af22d250fee7fdac5b5c39c3f1b9bf185cdf5ed.jpeg)

I can probably look at the `_bulk` at some point if you still need that

---

<div class="post-metadata">

**Author:** ![plissken](https://avatars.discourse-cdn.com/v4/letter/p/e0b2c6/32.png) [@plissken](https://discuss.elastic.co/u/plissken)\
**Post date:** [February 10, 2023, 4:53pm UTC](https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012/8 "2023-02-10T16:53:54Z")

</div>

That's great Stephen. Thanks for all the hard work on this. Feels like an individual object export and import might be the best way forward. I'll have a play over the weekend. Have a good one.

---

<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 10, 2023, 4:55pm UTC](https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012/9 "2023-02-10T16:55:49Z")

</div>

Its bugging me... 🙂 I will probably try the `_bulk` at some point

---

<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 10, 2023, 4:56pm UTC](https://discuss.elastic.co/t/curling-kibana-dashboards-exported-into-ndjson/325012/10 "2023-03-10T16:56:37Z")

</div>

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