Create a Vega library item Generally available

POST /api/vega

Spaces method and path for this operation:

post /s/{space_id}/api/vega

Refer to Spaces for more information.

Creates a new Vega library item and returns its ID, full state, and metadata.

Headers

  • kbn-xsrf string Required

    A required header to protect against CSRF attacks

application/json

Body

  • description string

    A short description of the Vega library item.

    Minimum length is 0, maximum length is 10000.

  • filters array[object]

    Filters. Applied together with the dashboard filters to Elasticsearch and ES|QL data sources that use %context%: true, and to Elasticsearch data sources that use %dashboard_context-*% placeholders.

    Not more than 100 elements.

    A filter applied to query results. Can be a field condition (condition), a logical group of conditions (group), a raw Elasticsearch DSL query (dsl), or a geo spatial query (spatial).

    One of:
  • query object

    KQL or Lucene query. Applied together with the dashboard query to Elasticsearch and ES|QL data sources that use %context%: true, and to Elasticsearch data sources that use %dashboard_context-*% placeholders.

    Additional properties are NOT allowed.

    Hide query attributes Show query attributes object
    • expression string Required

      A query expression in KQL or Lucene syntax.

      Minimum length is 0, maximum length is 1000000.

    • language string Required

      Query language. Use kql for Kibana Query Language (KQL) or lucene for Lucene query syntax.

      Values are kql or lucene.

  • spec object Required

    The Vega or Vega-Lite specification. Use { "format": "hjson", "value": "<hjson-string>" } for HJSON (comments and unquoted keys are preserved) or { "format": "json", "value": { ... } } for a JSON object.

    One of:
  • tags array[string]

    Tag IDs associated with this library item.

    Not more than 1000 elements. Maximum length of each is 250. Default value is [] (empty).

  • title string Required

    The Vega library item title.

    Minimum length is 1, maximum length is 1024.

Responses

  • 201 application/json

    created

    Hide response attributes Show response attributes object
    • data object Required

      Additional properties are NOT allowed.

      Hide data attributes Show data attributes object
      • description string

        A short description of the Vega library item.

        Minimum length is 0, maximum length is 10000.

      • filters array[object]

        Filters. Applied together with the dashboard filters to Elasticsearch and ES|QL data sources that use %context%: true, and to Elasticsearch data sources that use %dashboard_context-*% placeholders.

        Not more than 100 elements.

        A filter applied to query results. Can be a field condition (condition), a logical group of conditions (group), a raw Elasticsearch DSL query (dsl), or a geo spatial query (spatial).

        One of:
      • query object

        KQL or Lucene query. Applied together with the dashboard query to Elasticsearch and ES|QL data sources that use %context%: true, and to Elasticsearch data sources that use %dashboard_context-*% placeholders.

        Additional properties are NOT allowed.

        Hide query attributes Show query attributes object
        • expression string Required

          A query expression in KQL or Lucene syntax.

          Minimum length is 0, maximum length is 1000000.

        • language string Required

          Query language. Use kql for Kibana Query Language (KQL) or lucene for Lucene query syntax.

          Values are kql or lucene.

      • spec object Required

        The Vega or Vega-Lite specification. Use { "format": "hjson", "value": "<hjson-string>" } for HJSON (comments and unquoted keys are preserved) or { "format": "json", "value": { ... } } for a JSON object.

        One of:
      • tags array[string]

        Tag IDs associated with this library item.

        Not more than 1000 elements. Maximum length of each is 250. Default value is [] (empty).

      • title string Required

        The Vega library item title.

        Minimum length is 1, maximum length is 1024.

    • id string Required

      The unique ID of the Vega library item, as returned by the create or search endpoints.

    • meta object Required

      Additional properties are NOT allowed.

      Hide meta attributes Show meta attributes object
      • created_at string

        Timestamp when the object was created (ISO 8601).

      • created_by string

        User profile ID of the user who created the object.

      • managed boolean

        When true, the object is managed by Kibana and cannot be edited by users.

      • owner string

        Identifier of the plugin or team that owns this object.

      • updated_at string

        Timestamp when the object was last updated (ISO 8601).

      • updated_by string

        User profile ID of the user who last updated the object.

      • version string

        Internal version identifier for optimistic concurrency control.

  • 400

    invalid request

  • 403

    forbidden

  • 404

    not found

POST /api/vega
curl -X POST "${KIBANA_URL}/api/vega" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "kbn-xsrf: true" \
  -H "Content-Type: application/json" \
  -d '{
  "title": "Requests over time",
  "description": "Hourly request count from the sample web logs.",
  "spec": {
    "format": "hjson",
    "value": "{\n  $schema: https://vega.github.io/schema/vega-lite/v5.json\n  // Applies the dashboard time range, query, and filters\n  data: {\n    url: {\n      %context%: true\n      %timefield%: timestamp\n      index: kibana_sample_data_logs\n      body: {\n        size: 0\n        aggs: { hours: { date_histogram: { field: \"timestamp\", fixed_interval: \"1h\" } } }\n      }\n    }\n    format: { property: \"aggregations.hours.buckets\" }\n  }\n  mark: line\n  encoding: {\n    x: { field: \"key\", type: \"temporal\", title: null }\n    y: { field: \"doc_count\", type: \"quantitative\", title: \"Requests\" }\n  }\n}"
  }
}'
POST kbn:/api/vega
{
  "title": "Requests over time",
  "description": "Hourly request count from the sample web logs.",
  "spec": {
    "format": "hjson",
    "value": "{\n  $schema: https://vega.github.io/schema/vega-lite/v5.json\n  // Applies the dashboard time range, query, and filters\n  data: {\n    url: {\n      %context%: true\n      %timefield%: timestamp\n      index: kibana_sample_data_logs\n      body: {\n        size: 0\n        aggs: { hours: { date_histogram: { field: \"timestamp\", fixed_interval: \"1h\" } } }\n      }\n    }\n    format: { property: \"aggregations.hours.buckets\" }\n  }\n  mark: line\n  encoding: {\n    x: { field: \"key\", type: \"temporal\", title: null }\n    y: { field: \"doc_count\", type: \"quantitative\", title: \"Requests\" }\n  }\n}"
  }
}
Request examples
The filters and query are applied to data sources that use `%context%: true`, together with the dashboard query and filters.
{
  "filters": [
    {
      "condition": {
        "field": "geo.dest",
        "operator": "is",
        "value": "US"
      },
      "data_view_id": "90943e30-9a47-11e8-b64d-95841ca0b247",
      "type": "condition"
    },
    {
      "dsl": {
        "range": {
          "bytes": {
            "gte": 1000
          }
        }
      },
      "type": "dsl"
    }
  ],
  "query": {
    "expression": "machine.os.keyword : \"osx\"",
    "language": "kql"
  },
  "spec": {
    "format": "json",
    "value": {
      "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
      "data": {
        "format": {
          "property": "aggregations.extensions.buckets"
        },
        "url": {
          "%context%": true,
          "%timefield%": "timestamp",
          "body": {
            "aggs": {
              "extensions": {
                "terms": {
                  "field": "extension.keyword"
                }
              }
            },
            "size": 0
          },
          "index": "kibana_sample_data_logs"
        }
      },
      "encoding": {
        "x": {
          "field": "key",
          "type": "nominal"
        },
        "y": {
          "field": "doc_count",
          "type": "quantitative"
        }
      },
      "mark": "bar"
    }
  },
  "title": "Top extensions (US, macOS)"
}
{
  "description": "Hourly request count from the sample web logs.",
  "spec": {
    "format": "hjson",
    "value": "{\n  $schema: https://vega.github.io/schema/vega-lite/v5.json\n  // Applies the dashboard time range, query, and filters\n  data: {\n    url: {\n      %context%: true\n      %timefield%: timestamp\n      index: kibana_sample_data_logs\n      body: {\n        size: 0\n        aggs: { hours: { date_histogram: { field: \"timestamp\", fixed_interval: \"1h\" } } }\n      }\n    }\n    format: { property: \"aggregations.hours.buckets\" }\n  }\n  mark: line\n  encoding: {\n    x: { field: \"key\", type: \"temporal\", title: null }\n    y: { field: \"doc_count\", type: \"quantitative\", title: \"Requests\" }\n  }\n}"
  },
  "title": "Requests over time"
}
Response examples (201)
Returns the generated ID, the full item state in `data`, and metadata.
{
  "data": {
    "description": "Hourly request count from the sample web logs.",
    "spec": {
      "format": "hjson",
      "value": "{\n  $schema: https://vega.github.io/schema/vega-lite/v5.json\n  // Applies the dashboard time range, query, and filters\n  data: {\n    url: {\n      %context%: true\n      %timefield%: timestamp\n      index: kibana_sample_data_logs\n      body: {\n        size: 0\n        aggs: { hours: { date_histogram: { field: \"timestamp\", fixed_interval: \"1h\" } } }\n      }\n    }\n    format: { property: \"aggregations.hours.buckets\" }\n  }\n  mark: line\n  encoding: {\n    x: { field: \"key\", type: \"temporal\", title: null }\n    y: { field: \"doc_count\", type: \"quantitative\", title: \"Requests\" }\n  }\n}"
    },
    "title": "Requests over time"
  },
  "id": "7c1d8e40-9b2f-11f0-a5c3-2f6e4b8d9a10",
  "meta": {
    "created_at": "2026-09-30T10:00:00.000Z",
    "managed": false,
    "updated_at": "2026-09-30T10:00:00.000Z",
    "version": "WzU5LDFd"
  }
}