2019-03-08 19:18:36 +01:00
[[saved-objects-api-import]]
2019-09-06 18:09:57 +02:00
=== Import objects API
++++
<titleabbrev>Import objects</titleabbrev>
++++
2019-03-08 19:18:36 +01:00
2019-10-16 22:10:40 +02:00
experimental[] Create sets of {kib} saved objects from a file created by the export API.
2019-03-08 19:18:36 +01:00
2019-09-06 18:09:57 +02:00
[[saved-objects-api-import-request]]
2019-03-08 19:18:36 +01:00
==== Request
`POST /api/saved_objects/_import`
2019-10-18 19:17:54 +02:00
`POST /s/<space_id>/api/saved_objects/_import`
[[saved-objects-api-import-path-params]]
==== Path parameters
`space_id`::
(Optional, string) An identifier for the space. If `space_id` is not provided in the URL, the default space is used.
2019-09-06 18:09:57 +02:00
[[saved-objects-api-import-query-params]]
2019-10-18 19:17:54 +02:00
==== Query parameters
2019-03-08 19:18:36 +01:00
2019-09-06 18:09:57 +02:00
`overwrite`::
(Optional, boolean) Overwrites saved objects.
2019-03-08 19:18:36 +01:00
2019-09-06 18:09:57 +02:00
[[saved-objects-api-import-request-body]]
2019-03-08 19:18:36 +01:00
==== Request body
2019-09-06 18:09:57 +02:00
The request body must include the multipart/form-data type.
2019-03-08 19:18:36 +01:00
`file`::
A file exported using the export API.
2019-09-06 18:09:57 +02:00
[[saved-objects-api-import-response-body]]
2019-03-08 19:18:36 +01:00
==== Response body
2019-10-18 19:17:54 +02:00
`success`::
Top-level property that indicates if the import was successful.
2019-09-06 18:09:57 +02:00
2019-10-18 19:17:54 +02:00
`successCount`::
2019-09-06 18:09:57 +02:00
Indicates the number of successfully imported records.
`errors`::
(array) Indicates the import was unsuccessful and specifies the objects that failed to import.
2019-10-18 19:17:54 +02:00
2019-09-06 18:09:57 +02:00
[[saved-objects-api-import-codes]]
==== Response code
2019-10-18 19:17:54 +02:00
`200`::
2019-09-06 18:09:57 +02:00
Indicates a successful call.
2019-03-08 19:18:36 +01:00
==== Examples
2019-09-06 18:09:57 +02:00
Import an index pattern and dashboard:
2019-03-08 19:18:36 +01:00
[source,js]
--------------------------------------------------
2020-01-28 06:03:06 +01:00
$ curl -X POST "localhost:5601/api/saved_objects/_import" -H "kbn-xsrf: true" --form file=@file.ndjson
2019-06-05 13:49:47 +02:00
--------------------------------------------------
2019-09-06 18:09:57 +02:00
The `file.ndjson` file contains the following:
2019-03-08 19:18:36 +01:00
2019-06-05 13:49:47 +02:00
[source,js]
--------------------------------------------------
2019-03-08 19:18:36 +01:00
{"type":"index-pattern","id":"my-pattern","attributes":{"title":"my-pattern-*"}}
{"type":"dashboard","id":"my-dashboard","attributes":{"title":"Look at my dashboard"}}
--------------------------------------------------
2019-09-06 18:09:57 +02:00
The API returns the following:
2019-03-08 19:18:36 +01:00
[source,js]
--------------------------------------------------
{
"success": true,
"successCount": 2
}
--------------------------------------------------
2019-09-06 18:09:57 +02:00
Import an index pattern and dashboard that includes a conflict on the index pattern:
2019-03-08 19:18:36 +01:00
[source,js]
--------------------------------------------------
2019-06-05 13:49:47 +02:00
$ curl -X POST "localhost:5601/api/saved_objects/_import" -H "kbn-xsrf: true" --form file=@file.ndjson
--------------------------------------------------
2019-09-06 18:09:57 +02:00
The `file.ndjson` file contains the following:
2019-03-08 19:18:36 +01:00
2019-06-05 13:49:47 +02:00
[source,js]
--------------------------------------------------
2019-03-08 19:18:36 +01:00
{"type":"index-pattern","id":"my-pattern","attributes":{"title":"my-pattern-*"}}
{"type":"dashboard","id":"my-dashboard","attributes":{"title":"Look at my dashboard"}}
--------------------------------------------------
2019-09-06 18:09:57 +02:00
The API returns the following:
2019-03-08 19:18:36 +01:00
[source,js]
--------------------------------------------------
{
"success": false,
"successCount": 1,
"errors": [
{
"id": "my-pattern",
"type": "index-pattern",
2019-04-04 15:10:54 +02:00
"title": "my-pattern-*",
2019-03-08 19:18:36 +01:00
"error": {
2019-04-04 15:10:54 +02:00
"type": "conflict"
2019-03-08 19:18:36 +01:00
},
},
],
}
--------------------------------------------------
2019-04-04 15:10:54 +02:00
2019-09-06 18:09:57 +02:00
Import a visualization and dashboard with an index pattern for the visualization reference that doesn't exist:
2019-04-04 15:10:54 +02:00
[source,js]
--------------------------------------------------
2019-06-05 13:49:47 +02:00
$ curl -X POST "localhost:5601/api/saved_objects/_import" -H "kbn-xsrf: true" --form file=@file.ndjson
--------------------------------------------------
2019-04-04 15:10:54 +02:00
2019-09-06 18:09:57 +02:00
The `file.ndjson` file contains the following:
2019-06-05 13:49:47 +02:00
[source,js]
--------------------------------------------------
2019-04-04 15:10:54 +02:00
{"type":"visualization","id":"my-vis","attributes":{"title":"my-vis"},"references":[{"name":"ref_0","type":"index-pattern","id":"my-pattern-*"}]}
{"type":"dashboard","id":"my-dashboard","attributes":{"title":"Look at my dashboard"},"references":[{"name":"ref_0","type":"visualization","id":"my-vis"}]}
--------------------------------------------------
2019-09-06 18:09:57 +02:00
The API returns the following:
2019-04-04 15:10:54 +02:00
[source,js]
--------------------------------------------------
"success": false,
"successCount": 0,
"errors": [
{
"id": "my-vis",
"type": "visualization",
"title": "my-vis",
"error": {
"type": "missing_references",
"references": [
{
"type": "index-pattern",
"id": "my-pattern-*"
}
],
"blocking": [
{
"type": "dashboard",
"id": "my-dashboard"
}
]
}
}
]
--------------------------------------------------