2018-07-10 15:38:39 +02:00
[[saved-objects-api-bulk-create]]
2019-09-06 18:09:57 +02:00
=== Bulk create saved objects API
++++
2019-10-16 22:10:40 +02:00
<titleabbrev>Bulk create saved objects</titleabbrev>
2019-09-06 18:09:57 +02:00
++++
2018-07-10 15:38:39 +02:00
2019-09-18 17:54:28 +02:00
experimental[] Create multiple {kib} saved objects.
2018-12-05 22:20:58 +01:00
2019-09-06 18:09:57 +02:00
[[saved-objects-api-bulk-create-request]]
2018-07-10 15:38:39 +02:00
==== Request
2020-03-20 22:33:20 +01:00
`POST <kibana host>:<port>/api/saved_objects/_bulk_create`
2018-07-10 15:38:39 +02:00
2020-03-20 22:33:20 +01:00
`POST <kibana host>:<port>/s/<space_id>/api/saved_objects/_bulk_create`
2019-10-18 19:17:54 +02:00
[[saved-objects-api-bulk-create-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-bulk-create-query-params]]
==== Query parameters
2018-07-10 15:38:39 +02:00
2019-09-06 18:09:57 +02:00
`overwrite`::
(Optional, boolean) When `true`, overwrites the document with the same ID.
2018-07-10 15:38:39 +02:00
2019-09-06 18:09:57 +02:00
[[saved-objects-api-bulk-create-request-body]]
==== Request body
2018-07-10 15:38:39 +02:00
2019-09-06 18:09:57 +02:00
`type`::
(Required, string) Valid options include `visualization`, `dashboard`, `search`, `index-pattern`, `config`, and `timelion-sheet`.
2018-07-10 15:38:39 +02:00
2019-09-06 18:09:57 +02:00
`id`::
(Optional, string) Specifies an ID instead of using a randomly generated ID.
2018-07-10 15:38:39 +02:00
2019-09-06 18:09:57 +02:00
`attributes`::
(Required, object) The data that you want to create.
2018-07-10 15:38:39 +02:00
2019-09-06 18:09:57 +02:00
`references`::
(Optional, array) Objects with `name`, `id`, and `type` properties that describe the other saved objects in the referenced object. To refer to the other saved object, use `name` in the attributes. Never use `id` to refer to the other saved object. `id` can be automatically updated during migrations, import, or export.
2018-07-10 15:38:39 +02:00
2020-10-06 23:01:26 +02:00
`initialNamespaces`::
2020-10-07 00:00:23 +02:00
(Optional, string array) Identifiers for the <<xpack-spaces,spaces>> in which this object is created. If this is provided, the
object is created only in the explicitly defined spaces. If this is not provided, the object is created in the current space
(default behavior).
2020-10-05 05:28:49 +02:00
2019-09-06 18:09:57 +02:00
`version`::
(Optional, number) Specifies the version.
2018-07-10 15:38:39 +02:00
2019-09-06 18:09:57 +02:00
[[saved-objects-api-bulk-create-response-body]]
2018-07-10 15:38:39 +02:00
==== Response body
2019-10-18 19:17:54 +02:00
`saved_objects`::
2019-09-06 18:09:57 +02:00
(array) Top-level property the contains objects that represent the response for each of the requested objects. The order of the objects in the response is identical to the order of the objects in the request.
Saved objects that are unable to persist are replaced with an error object.
2018-07-10 15:38:39 +02:00
2019-09-06 18:09:57 +02:00
[[saved-objects-api-bulk-create-codes]]
==== Response code
2018-07-10 15:38:39 +02:00
2019-10-18 19:17:54 +02:00
`200`::
2019-09-06 18:09:57 +02:00
Indicates a successful call.
2018-07-10 15:38:39 +02:00
2019-09-06 18:09:57 +02:00
[[saved-objects-api-bulk-create-example]]
==== Example
2018-07-10 15:38:39 +02:00
2019-10-18 19:17:54 +02:00
Create an index pattern with the `my-pattern` ID, and a dashboard with the `my-dashboard` ID:
2018-07-10 15:38:39 +02:00
2020-03-20 22:33:20 +01:00
[source,sh]
2018-07-10 15:38:39 +02:00
--------------------------------------------------
2020-07-14 21:59:21 +02:00
$ curl -X POST api/saved_objects/_bulk_create
2018-07-10 15:38:39 +02:00
[
{
"type": "index-pattern",
"id": "my-pattern",
"attributes": {
"title": "my-pattern-*"
}
},
{
"type": "dashboard",
2019-10-18 19:17:54 +02:00
"id": "be3733a0-9efe-11e7-acb3-3dab96693fab",
2018-07-10 15:38:39 +02:00
"attributes": {
"title": "Look at my dashboard"
}
}
]
--------------------------------------------------
// KIBANA
2019-09-06 18:09:57 +02:00
The API returns the following:
2018-07-10 15:38:39 +02:00
2020-03-20 22:33:20 +01:00
[source,sh]
2018-07-10 15:38:39 +02:00
--------------------------------------------------
{
"saved_objects": [
{
"id": "my-pattern",
"type": "index-pattern",
"version": 1,
"attributes": {
"title": "my-pattern-*"
}
},
{
2019-10-18 19:17:54 +02:00
"id": "be3733a0-9efe-11e7-acb3-3dab96693fab",
2018-07-10 15:38:39 +02:00
"type": "dashboard",
"error": {
"statusCode": 409,
2020-04-10 05:18:18 +02:00
"message": "Saved object [dashboard/be3733a0-9efe-11e7-acb3-3dab96693fab] conflict"
2018-07-10 15:38:39 +02:00
}
}
]
}
--------------------------------------------------
2019-09-06 18:09:57 +02:00
There is already a saved object with the `my-dashboard` ID, so only the index pattern is created.