Import saved objects through API

Hello,

To summarize this post, I'm able to import Kibana saved objects using the web UI, but I face some issues importing them using the API.

We use a dashboard.ndjson file which is the result of a saved object export using the Kibana web UI on port 5601 (Stack Management / Saved objects / Export objects).

When I import this file using the Kibana web UI (Stack Management / Saved objects / Import), it works well: by clicking "Confirm all changes" in the the dialog box below which shows the index pattern conflicts, the saved objects are imported.

When I try to import the same file using the API, by typing the following command, some errors appears related to the same index pattern conflicts than the previous ones (see the image below), but this time the saved objects are not imported:

curl -X POST localhost:5601/api/saved_objects/_import?createNewCopies=true -H "kbn-xsrf: true" --form file=@dashboard.ndjson

So using the same dashboard.ndjson file, I'm able to import it using the web UI but not using the API. Do you have any idea on how to import it using the API ?

ah right. We can resolve this in UI but not sure what to do with API.

@afharo / @Pierre_Gayvallet any ideas?

Thanks,
Bhavya

After looking closer at the code and screenshots, I believe the UI is simply removing those conflicting saved objects from the list of saved objects to import.

It seems that the selected option for all 3 conflicts is -- Skip Import --. AFAIK, the UI code will simply remove those Saved Objects from the list to import, and it will import the rest.

To mimic that behaviour via the API, I guess the app needs to remove those conflicting Saved Objects.