---
type: api
title: Create or update a runtime field
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/v8/operation/operation-createupdateruntimefielddefault
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/v8/operation/operation-createupdateruntimefielddefault
products:
  - Kibana
---

# Create or update a runtime field

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

## Paths

- `PUT` `/api/data_views/data_view/{viewId}/runtime_field`
- `PUT` `/s/{space_id}/api/data_views/data_view/{viewId}/runtime_field`

#### Path parameters

- `viewId` (string) — required
  The ID of the data view fields you want to update.

## Description

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

## Authentication

- Api key: `Authorization: <value>`
  These APIs use key-based authentication. You must create an API key and use the encoded value in the request header. For example: `Authorization: ApiKey base64AccessApiKey`
- Basic: `Authorization: Basic <credentials>`

## Header parameters

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

## Request body

`application/json`

- `name` (string) — required
  The name for a runtime field.
- `runtimeField` (object) — required
  The runtime field definition object.

## Responses

#### `200`

Indicates a successful call.

`application/json`

- `data_view` (object)
- `fields` (object[])
#### `400`

Bad request

`application/json`

- `error` (string)
- `message` (string)
- `statusCode` (number)
## Code examples

#### Console

```console
PUT kbn:/api/data_views/data_view/VIEW_ID/runtime_field
{
  "name": "runtimeFoo",
  "runtimeField": {
    "script": {
      "source": "emit(doc[\u0022foo\u0022].value)"
    },
    "type": "long"
  }
}
```

#### curl

```curl
curl -X PUT "${KIBANA_URL}/api/data_views/data_view/${VIEW_ID}/runtime_field" \
  -H "kbn-xsrf: true" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "runtimeFoo",
    "runtimeField": {
      "script": {
        "source": "emit(doc[\u0022foo\u0022].value)"
      },
      "type": "long"
    }
  }'
```

