Copy saved objects between spaces

POST /api/spaces/_copy_saved_objects

It also allows you to automatically copy related objects, so when you copy a dashboard, this can automatically copy over the associated visualizations, data views, and saved searches, as required. You can request to overwrite any objects that already exist in the target space if they share an identifier or you can use the resolve copy saved objects conflicts API to do this on a per-object basis.

[Required authorization] Route required privileges: ALL of [copySavedObjectsToSpaces].

Headers

  • kbn-xsrf string Required

    A required header to protect against CSRF attacks

application/json; Elastic-Api-Version=2023-10-31

Body

  • Apply various adjustments to the saved objects that are being copied to maintain compatibility between different Kibana versions. Use this option only if you encounter issues with copied saved objects. This option cannot be used with the createNewCopies option.

    Default value is false.

  • Create new copies of saved objects, regenerate each object identifier, and reset the origin. When used, potential conflict errors are avoided. This option cannot be used with the overwrite and compatibilityMode options.

    Default value is true.

  • When set to true, all saved objects related to the specified saved objects will also be copied into the target spaces.

    Default value is false.

  • objects array[object] Required
    Hide objects attributes Show objects attributes object
    • id string Required

      The identifier of the saved object to copy.

    • type string Required

      The type of the saved object to copy.

  • overwrite boolean

    When set to true, all conflicts are automatically overridden. When a saved object with a matching type and identifier exists in the target space, that version is replaced with the version from the source space. This option cannot be used with the createNewCopies option.

    Default value is false.

  • spaces array[string] Required

    The identifiers of the spaces where you want to copy the specified objects.

Responses

  • 200 application/json; Elastic-Api-Version=2023-10-31
POST /api/spaces/_copy_saved_objects
curl \
 -X POST https://localhost:5601/api/spaces/_copy_saved_objects \
 -H "Content-Type: application/json; Elastic-Api-Version=2023-10-31" \
 -H "kbn-xsrf: true"
Request examples
Copy a dashboard with the my-dashboard ID, including all references from the default space to the marketing space. In this example, the dashboard has a reference to a visualization and that has a reference to a data view.
{
  "spaces": [
    "marketing"
  ],
  "objects": [
    {
      "id": "my-dashboard",
      "type": "dashboard"
    }
  ],
  "includeReferences": true
}
Copy a dashboard with the my-dashboard ID, including all references from the default space to the marketing space. In this example, the dashboard has a reference to a visualization and that has a reference to a data view.
{
  "spaces": [
    "marketing"
  ],
  "objects": [
    {
      "id": "my-dashboard",
      "type": "dashboard"
    }
  ],
  "createNewCopies": false,
  "includeReferences": true
}
The response for successfully copying a dashboard with the my-dashboard ID, including all references from the default space to the marketing space. The result indicates a successful copy and all three objects are created. Since these objects were created as new copies, each entry in the successResults array includes a destinationId attribute.
{
  "marketing": {
    "success": true,
    "successCount": 3,
    "successResults": [
      {
        "id": "my-dashboard",
        "meta": {
          "icon": "dashboardApp",
          "title": "Look at my dashboard"
        },
        "type": "dashboard",
        "destinationId": "1e127098-5b80-417f-b0f1-c60c8395358f"
      },
      {
        "id": "my-vis",
        "meta": {
          "icon": "visualizeApp",
          "title": "Look at my visualization"
        },
        "type": "visualization",
        "destinationId": "a610ed80-1c73-4507-9e13-d3af736c8e04"
      },
      {
        "id": "my-index-pattern",
        "meta": {
          "icon": "indexPatternApp",
          "title": "my-pattern-*"
        },
        "type": "index-pattern",
        "destinationId": "bc3c9c70-bf6f-4bec-b4ce-f4189aa9e26b"
      }
    ]
  }
}
The response for successfully copying a dashboard with the my-dashboard ID with createNewCopies turned off. The result indicates a successful copy and all three objects are created.
{
  "marketing": {
    "success": true,
    "successCount": 3,
    "successResults": [
      {
        "id": "my-dashboard",
        "meta": {
          "icon": "dashboardApp",
          "title": "Look at my dashboard"
        },
        "type": "dashboard"
      },
      {
        "id": "my-vis",
        "meta": {
          "icon": "visualizeApp",
          "title": "Look at my visualization"
        },
        "type": "visualization"
      },
      {
        "id": "my-index-pattern",
        "meta": {
          "icon": "indexPatternApp",
          "title": "my-pattern-*"
        },
        "type": "index-pattern"
      }
    ]
  }
}
A response for a failed copy of a dashboard with the my-dashboard ID including all references from the default space to the marketing and sales spaces. In this example, the dashboard has a reference to a visualization and a Canvas workpad and the visualization has a reference to an index pattern. The result indicates a successful copy for the marketing space and an unsuccessful copy for the sales space because the data view, visualization, and Canvas workpad each resulted in a conflict error. Objects are created when the error is resolved using the resolve copy conflicts API.
{
  "sales": {
    "errors": [
      {
        "id": "my-pattern",
        "meta": {
          "icon": "indexPatternApp",
          "title": "my-pattern-*"
        },
        "type": "index-pattern",
        "error": {
          "type": "conflict"
        },
        "title": "my-pattern-*"
      },
      {
        "id": "my-visualization",
        "meta": {
          "icon": "visualizeApp",
          "title": "Look at my visualization"
        },
        "type": "my-vis",
        "error": {
          "type": "conflict",
          "destinationId": "another-vis"
        },
        "title": "Look at my visualization"
      },
      {
        "id": "my-canvas",
        "meta": {
          "icon": "canvasApp",
          "title": "Look at my canvas"
        },
        "type": "canvas-workpad",
        "error": {
          "type": "ambiguous_conflict",
          "destinations": [
            {
              "id": "another-canvas",
              "title": "Look at another canvas",
              "updatedAt": "2020-07-08T16:36:32.377Z"
            },
            {
              "id": "yet-another-canvas",
              "title": "Look at yet another canvas",
              "updatedAt": "2020-07-05T12:29:54.849Z"
            }
          ]
        },
        "title": "Look at my canvas"
      }
    ],
    "success": false,
    "successCount": "1,",
    "successResults\"": [
      {
        "id": "my-dashboard",
        "meta": {
          "icon": "dashboardApp",
          "title": "Look at my dashboard"
        },
        "type": "dashboard"
      }
    ]
  },
  "marketing": {
    "success": true,
    "successCount": 4,
    "successResults": [
      {
        "id": "my-dashboard",
        "meta": {
          "icon": "dashboardApp",
          "title": "Look at my dashboard"
        },
        "type": "dashboard"
      },
      {
        "id": "my-vis",
        "meta": {
          "icon": "visualizeApp",
          "title": "Look at my visualization"
        },
        "type": "visualization"
      },
      {
        "id": "my-canvas",
        "meta": {
          "icon": "canvasApp",
          "title": "Look at my canvas"
        },
        "type": "canvas-workpad"
      },
      {
        "id": "my-index-pattern",
        "meta": {
          "icon": "indexPatternApp",
          "title": "my-pattern-*"
        },
        "type": "index-pattern"
      }
    ]
  }
}
The response for successfully copying a dashboard with the my-dashboard ID, including all references from the default space to the marketing space. In this example, the dashboard has a reference to a visualization and a Canvas workpad and the visualization has a reference to a data view. The result indicates an unsuccessful copy because the visualization resulted in a missing references error. Objects are created when the errors are resolved using the resolve copy conflicts API.
{
  "marketing": {
    "errors": [
      {
        "id": "my-vis",
        "meta": {
          "icon": "visualizeApp",
          "title": "Look at my visualization"
        },
        "type": "visualization",
        "error": {
          "type": "missing_references",
          "references": [
            {
              "id": "my-pattern-*",
              "type": "index-pattern"
            }
          ]
        },
        "title": "Look at my visualization"
      }
    ],
    "success": false,
    "successCount": 2,
    "successResults": [
      {
        "id": "my-dashboard",
        "meta": {
          "icon": "dashboardApp",
          "title": "Look at my dashboard"
        },
        "type": "dashboard"
      },
      {
        "id": "my-canvas",
        "meta": {
          "icon": "canvasApp",
          "title": "Look at my canvas"
        },
        "type": "canvas-workpad"
      }
    ]
  }
}