Copy saved objects to space APIedit

[experimental] This functionality is experimental and may be changed or removed completely in a future release. Elastic will take a best effort approach to fix any issues, but experimental features are not subject to the support SLA of official GA features. Copy saved objects between spaces.

It also allows you to automatically copy related objects, so when you copy a dashboard, this can automatically copy over the associated visualizations, index patterns, and saved searches, as required.

You can request to overwrite any objects that already exist in the target space if they share an ID, or you can use the Resolve copy saved objects conflicts API to do this on a per-object basis.

Requestedit

POST <kibana host>:<port>/api/spaces/_copy_saved_objects

POST <kibana host>:<port>/s/<space_id>/api/spaces/_copy_saved_objects

Path parametersedit

space_id
(Optional, string) The ID of the space that contains the saved objects you want to copy. When space_id is unspecified in the URL, the default space is used.

Request bodyedit

spaces
(Required, string array) The IDs of the spaces where you want to copy the specified objects.
objects

(Required, object array) The saved objects to copy.

Properties of objects
type
(Required, string) The saved object type.
id
(Required, string) The saved object ID.
includeReferences
(Optional, boolean) When set to true, all saved objects related to the specified saved objects will also be copied into the target spaces. The default value is false.
overwrite
(Optional, boolean) When set to true, all conflicts are automatically overidden. When a saved object with a matching type and id exists in the target space, that version is replaced with the version from the source space. The default value is false.

Response bodyedit

<space_id>

(object) An object that describes the result of the copy operation for the space. Includes the dynamic keys in the response.

Properties of <space_id>
success
(boolean) The copy operation was successful. When set to false, some objects may have been copied. For additional information, refer to the successCount and errors properties.
successCount
(number) The number of objects that successfully copied.
errors

(Optional, array) The errors that occurred during the copy operation. When errors are reported, the success flag is set to false.

Properties of errors
id
(string) The saved object ID that failed to copy.
type
(string) The type of saved object that failed to copy.
error

(object) The error that caused the copy operation to fail.

Properties of error
type:
(string) The type of error. For example, unsupported_type, missing_references, or unknown. Errors marked as conflict may be resolved by using the Resolve copy saved objects conflicts API.

Examplesedit

Copy a dashboard with the my-dashboard ID, including all references from the default space to the marketing and sales spaces:

$ curl -X POST "localhost:5601/api/spaces/_copy_saved_objects"
{
  "objects": [{
    "type": "dashboard",
    "id": "my-dashboard"
  }],
  "spaces": ["marketing", "sales"],
  "includeReferences": true
}

The API returns the following:

{
  "marketing": {
    "success": true,
    "successCount": 5
  },
  "sales": {
    "success": false,
    "successCount": 4,
    "errors": [{
      "id": "my-index-pattern",
      "type": "index-pattern",
      "error": {
        "type": "conflict"
      }
    }]
  }
}

The marketing space succeeds, but the sales space fails due to a conflict in the index pattern.

Copy a visualization with the my-viz ID from the marketing space to the default space:

$ curl -X POST "localhost:5601/s/marketing/api/spaces/_copy_saved_objects"
{
  "objects": [{
    "type": "visualization",
    "id": "my-viz"
  }],
  "spaces": ["default"]
}

The API returns the following:

{
  "default": {
    "success": true,
    "successCount": 1
  }
}