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

# Create a runtime field

Authentication: required

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

## Paths

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

#### 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.
- `viewId` (string) — required
  An identifier for the data view.
  Example: `ff959d40-b880-11e8-a6d9-e546fe2bba5f`

## 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.

## Response

Indicates a successful call.

`application/json`

Type: `object`

## Code examples

#### Console

```console
POST kbn:/api/data_views/data_view/ff959d40-b880-11e8-a6d9-e546fe2bba5f/runtime_field
{
  "name": "runtimeFoo",
  "runtimeField": {
    "script": {
      "source": "emit(doc[\u0022foo\u0022].value)"
    },
    "type": "long"
  }
}
```

#### curl

```curl
curl -X POST "${KIBANA_URL}/api/data_views/data_view/ff959d40-b880-11e8-a6d9-e546fe2bba5f/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"
    }
  }'
```

## 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
{}
```

