---
type: api
title: Swap saved object references
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/kibana/v8/operation/operation-swapdataviewsdefault
resource: https://www.elastic.co/elastic/docs-builder/docs/4641/api/doc/kibana/v8/operation/operation-swapdataviewsdefault
products:
  - Kibana
---

# Swap saved object references

Authentication: required

- Server: `https://{kibana_url}`

## Paths

- `POST` `/api/data_views/swap_references`
- `POST` `/s/{space_id}/api/data_views/swap_references`

#### Path parameters

- `space_id` (string) — optional
  An identifier for the space. If `space_id` is not provided in the URL, the default space is used. Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

## Description

Changes saved object references from one data view identifier to another. WARNING: Misuse can break large numbers of saved objects! Practicing with a backup is recommended.

## Header parameters

- `kbn-xsrf` (string) — required
  Cross-site request forgery protection

## Request body

`application/json`

- `delete` (boolean) — optional
  Deletes referenced saved object if all references are removed.
- `forId` (union string | string[]) — optional
  Limit the affected saved objects to one or more by identifier.
- `forType` (string) — optional
  Limit the affected saved objects by type.
- `fromId` (string) — required
  The saved object reference to change.
- `fromType` (string) — optional
  Specify the type of the saved object reference to alter. The default value is `index-pattern` for data views.
- `toId` (string) — required
  New saved object reference value to replace the old value.

## Response

Indicates a successful call.

`application/json`

- `deleteStatus` (object)
  - `deletePerformed` (boolean)
  - `remainingRefs` (integer)
- `result` (object[])
  - `id` (string)
    A saved object identifier.
  - `type` (string)
    The saved object type.
## Code examples

#### Console

```console
POST kbn:/api/data_views/swap_references
{
  "delete": true,
  "fromId": "abcd-efg",
  "toId": "xyz-123"
}
```

#### curl

```curl
curl -X POST "${KIBANA_URL}/api/data_views/swap_references" \
  -H "kbn-xsrf: true" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "delete": true,
    "fromId": "abcd-efg",
    "toId": "xyz-123"
  }'
```

## Response examples

#### 200

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{
  "deleteStatus": {
    "deletePerformed": false,
    "remainingRefs": 0
  },
  "result": [
    {
      "id": "string",
      "type": "string"
    }
  ]
}
```

