You are right, I'm sorry, the issue I was reporting about the incompatibility of exported saved objects between API and GUI doesn't exist in the case the GUI you are referring to is the Management -> Saved Objects (I was referring to exporting a dashboard saved object from the Dashboard UI and importing it through API). Sorry for the confusion.
I have around more than 100 saved object files and explicitly export individual object with API and then saving in a separate ndjson file and then import with API is a very tedious job. Is there any better way to achieve it?
Sure, you can export saved object by types and you can download all types at ones with this:
https://www.elastic.co/guide/en/kibana/current/saved-objects-api-export.html
POST api/saved_objects/_export
{
"type": [
"config",
"map",
"canvas-workpad",
"canvas-element",
"index-pattern",
"visualization",
"search",
"dashboard",
"url"
],
"includeReferencesDeep": true
}
This will return all the saved object available in kibana (is exactly the same function called by the UI when you export all your objects.
Than you can import that using
https://www.elastic.co/guide/en/kibana/current/saved-objects-api-import.html
$ curl -X POST "localhost:5601/api/saved_objects/_import" -H "kbn-xsrf: true" --form file=@YOUR_EXPORTED_FILENAME.ndjson
And it should import all your object.
The response should also contains a message like the following that contains the number of imported objects, and the status of the import (together with errors if any)
{
"success": false,
"successCount": 1,
"errors": [
// list of errors
]