# Kibana dashboard import api fails

**URL:** https://discuss.elastic.co/t/kibana-dashboard-import-api-fails/265603
**Category:** Kibana
**Created:** [February 26, 2021, 11:20am UTC](https://discuss.elastic.co/t/kibana-dashboard-import-api-fails/265603 "2021-02-26T11:20:52Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![vaclav1](https://avatars.discourse-cdn.com/v4/letter/v/c68b51/32.png) [@vaclav1](https://discuss.elastic.co/u/vaclav1)
#### Post date: [February 26, 2021, 11:20am UTC](https://discuss.elastic.co/t/kibana-dashboard-import-api-fails/265603/1 "2021-02-26T11:20:52Z")

</div>

Dear team,

We use export api to export dashboard with other visualisations.  
This api url is used to export it:

```auto
GET <kibana host>:<port>/s/<space-id>/api/kibana/dashboards/export?dashboard=dashboard_id

```

Export produces a json file with no issues (find attached to this topic).

Import api used:

```auto
POST <kibana host>:<port>/s/<space-id>/api/kibana/dashboards/import

```

But when we try to import it we get following response:

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

```

We are using currently 7.9 version of Elasticstack.

I am not able to attach the exported Json here (too many chars issues) but I could send possibly via other channel.

---

<div class="post-metadata">

### Author: ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)
#### Post date: [February 26, 2021, 8:36pm UTC](https://discuss.elastic.co/t/kibana-dashboard-import-api-fails/265603/2 "2021-02-26T20:36:00Z")

</div>

Hi @vaclav1,

How are you formatting your import request? I just ran a test in a 7.9 Elastic cloud cluster and was able to successfully import/export using the dashboard API. Here's what I did:

```auto
curl --http1.0 -H "Authorization: ApiKey MY_API_KEY" https://<kibana_host>:<port>/api/kibana/dashboards/export?dashboard=abc123 > export.json

```

And then to re-import the exported file:

```auto
curl --http1.0 -X POST -H "kbn-xsrf: whatever" -H "Authorization: ApiKey MY_API_KEY" -H "content-type: application/json" https://<kibana_host>:<port>/api/kibana/dashboards/import -d @export.json

```

I didn't have to make any changes to the exported json in order for this to work. (Also note that here I used an ApiKey for authentication, but api keys aren't strictly necessary for this API... any method of authentication will work.)

---

<div class="post-metadata">

### Author: ![vaclav1](https://avatars.discourse-cdn.com/v4/letter/v/c68b51/32.png) [@vaclav1](https://discuss.elastic.co/u/vaclav1)
#### Post date: [March 1, 2021, 7:18am UTC](https://discuss.elastic.co/t/kibana-dashboard-import-api-fails/265603/3 "2021-03-01T07:18:54Z")

</div>

Helo Luke, thanks for your answer. Will try it out, colleague of mine does it in python. And will get back if this will not work.

---

<div class="post-metadata">

### Author: ![vaclav1](https://avatars.discourse-cdn.com/v4/letter/v/c68b51/32.png) [@vaclav1](https://discuss.elastic.co/u/vaclav1)
#### Post date: [March 1, 2021, 8:52am UTC](https://discuss.elastic.co/t/kibana-dashboard-import-api-fails/265603/4 "2021-03-01T08:52:58Z")

</div>

Ok I have got a following issue while importing:

```auto
{"type":"log","@timestamp":"2021-03-01T08:48:11Z","tags":["warning","savedobjects-service"],"pid":68610,"message":"Failed to transform document [object Object]. Transform: index-pattern:6.5.0\nDoc: {\"id\":\"15eb5d40-8b12-11ea-b95c-fd8b76e35998\",\"type\":\"index-pattern\",\"migrationVersion\":{},\"namespace\":\"datasquad-space\",\"updated_at\":\"2021-03-01T08:48:11.331Z\",\"references\":[]}"}
{"type":"log","@timestamp":"2021-03-01T08:48:11Z","tags":["error","http"],"pid":68610,"message":"TypeError: Cannot read property 'type' of undefined\n at migrateAttributeTypeAndAttributeTypeMeta (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/plugins/data/server/saved_objects/index_pattern_migrations.js:30:26)\n at /app/global/kibana/kibana-7.9.2-linux-x86_64/node_modules/lodash/lodash.js:5135:46\n at tryTransformDoc (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/core/server/saved_objects/migrations/core/document_migrator.js:225:22)\n at migrateProp (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/core/server/saved_objects/migrations/core/document_migrator.js:282:11)\n at applyMigrations (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/core/server/saved_objects/migrations/core/document_migrator.js:181:11)\n at DocumentMigrator.transformAndValidate [as transformDoc] (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/core/server/saved_objects/migrations/core/document_migrator.js:160:43)\n at DocumentMigrator.doc [as migrate] (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/core/server/saved_objects/migrations/core/document_migrator.js:53:19)\n at KibanaMigrator.migrateDocument (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/core/server/saved_objects/migrations/kibana/kibana_migrator.js:166:34)\n at expectedResults.map.expectedBulkGetResult (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/core/server/saved_objects/service/lib/repository.js:320:74)\n at Array.map (<anonymous>)\n at SavedObjectsRepository.bulkCreate (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/core/server/saved_objects/service/lib/repository.js:275:49)\n at SavedObjectsClient.bulkCreate (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/core/server/saved_objects/service/saved_objects_client.js:46:35)\n at EncryptedSavedObjectsClientWrapper.bulkCreate (/app/global/kibana/kibana-7.9.2-linux-x86_64/x-pack/plugins/encrypted_saved_objects/server/saved_objects/encrypted_saved_objects_client_wrapper.js:88:93)\n at process._tickCallback (internal/process/next_tick.js:68:7)"}
{"type":"error","@timestamp":"2021-03-01T08:48:11Z","tags":[],"pid":68610,"level":"error","error":{"message":"Internal Server Error","name":"Error","stack":"Error: Internal Server Error\n at HapiResponseAdapter.toInternalError (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/core/server/http/router/response_adapter.js:69:19)\n at Router.handle (/app/global/kibana/kibana-7.9.2-linux-x86_64/src/core/server/http/router/router.js:170:34)\n at process._tickCallback (internal/process/next_tick.js:68:7)"},"url":{"protocol":null,"slashes":null,"auth":null,"host":null,"port":null,"hostname":null,"hash":null,"search":null,"query":{},"pathname":"/api/kibana/dashboards/import","path":"/api/kibana/dashboards/import","href":"/api/kibana/dashboards/import"},"message":"Internal Server Error"}
{"type":"response","@timestamp":"2021-03-01T08:48:11Z","tags":["api"],"pid":68610,"method":"post","statusCode":500,"req":{"url":"/api/kibana/dashboards/import","method":"post","headers":{"user-agent":"curl/7.29.0","host":"10.198.134.170:5601","accept":"*/*","content-type":"application/json","kbn-xsrf":"whatever","content-length":"245420"},"remoteAddress":"10.198.134.170","userAgent":"curl/7.29.0"},"res":{"statusCode":500,"responseTime":25,"contentLength":9},"message":"POST /api/kibana/dashboards/import 500 25ms - 9.0B"}

```

Any hints what might be wrong?

---

<div class="post-metadata">

### Author: ![lukeelmers](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukeelmers/32/35230_2.png) [@lukeelmers](https://discuss.elastic.co/u/lukeelmers)
#### Post date: [March 8, 2021, 8:41pm UTC](https://discuss.elastic.co/t/kibana-dashboard-import-api-fails/265603/5 "2021-03-08T20:41:11Z")

</div>

Thanks for the logs - these are super helpful! It looks like your import is failing because the saved objects migration system thinks the index pattern you are attempting to import is malformed.

Briefly looking at the code, it seems like you _might_ be able to get this to work by adding an `attributes` object to the index pattern:

```auto
{\"id\":\"15eb5d40-8b12-11ea-b95c-fd8b76e35998\",\"type\":\"index-pattern\",\"migrationVersion\":{},\"namespace\":\"datasquad-space\",\"updated_at\":\"2021-03-01T08:48:11.331Z\",\"references\":[], \"attributes\":{}}

```

Is this an index pattern you've written by hand, or did you get it directly via `/api/kibana/dashboards/export`? If you simply exported this directly and haven't modified the index pattern, that's more concerning as there may be a bug in either the export or migration code.

---

<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: [April 5, 2021, 8:41pm UTC](https://discuss.elastic.co/t/kibana-dashboard-import-api-fails/265603/6 "2021-04-05T20:41:59Z")

</div>

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