Kibana dashboard import api fails

Dear team,

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

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:

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

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

{"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.

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:

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:

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.)

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.

Ok I have got a following issue while importing:

{"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?

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:

{\"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.

1 Like

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