Copy saved objects to space API

edit

Copy saved objects to space API

edit

The underlying Spaces concepts are stable, but the APIs for managing Spaces are experimental.

Request

edit

POST /api/spaces/_copy_saved_objects

POST /s/<space_id>/api/spaces/_copy_saved_objects

Description

edit

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.

Path parameters

edit
space_id
(Optional, string) Identifies the source space from which saved objects will be copied. If space_id is not specified in the URL, the default space is used.

Request body

edit
spaces
(Required, string array) The ids of the spaces the specified object(s) will be copied into.
objects

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

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 will be automatically overidden. If a saved object with a matching type and id exists in the target space, then that version will be replaced with the version from the source space. The default value is false.

Response body

edit
<space_id>

(object) Specifies the dynamic keys that are included in the response. An object describing the result of the copy operation for this particular space.

success
(boolean) Indicates if the copy operation was successful. Note that some objects may have been copied even if this is set to false. Consult the successCount and errors properties of the response for additional information.
successCount
(number) The number of objects that were successfully copied.
errors

(Optional, array) Collection of any errors that were encountered during the copy operation. If any errors are reported, then the success flag will be set to false.

id
(string) The saved object id which failed to copy.
type
(string) The type of saved object which failed to copy.
error

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

type:
(string) Indicates the type of error. May be one of: conflict, unsupported_type, missing_references, unknown. Errors marked as conflict may be resolved by using the Resolve copy saved objects conflicts API.

Examples

edit

The following example attempts to copy a dashboard with id my-dashboard, including all references from the default space to the marketing and sales spaces. The marketing space succeeds, while the sales space fails due to a conflict on the underlying index pattern:

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

The API returns the following result:

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

The following example successfully copies a visualization with id my-viz from the marketing space to the default space:

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

The API returns the following result:

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