# API for creating scripted fields

**URL:** <https://discuss.elastic.co/t/api-for-creating-scripted-fields/139236>\
**Category:** Kibana\
**Created:** [July 9, 2018, 8:24pm UTC](https://discuss.elastic.co/t/api-for-creating-scripted-fields/139236 "2018-07-09T20:24:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sgarap](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@sgarap](https://discuss.elastic.co/u/sgarap)\
**Post date:** [July 9, 2018, 8:24pm UTC](https://discuss.elastic.co/t/api-for-creating-scripted-fields/139236/1 "2018-07-09T20:24:58Z")

</div>

Hi,

I created a couple of scripted fields using Kibana GUI and used them to create visualizations.  
I am now looking for a way to automate the creation of scripted fields and import dashboards. Is there an API available for doing the same? If not what is the easiest way to achieve this programmatically?

Regards.  
Sindhura

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [July 10, 2018, 2:05pm UTC](https://discuss.elastic.co/t/api-for-creating-scripted-fields/139236/2 "2018-07-10T14:05:45Z")

</div>

The UI is updating the `index-pattern` saved object with the new scripted field data. You could perform these steps programmatically. You can open the developer tools in your browser and add a scripted field to an index-pattern. The network tab will capture the interactions with the server so you can see how the UI is using Kibana's saved object API.

Use the [saved object GET API](https://www.elastic.co/guide/en/kibana/6.x/saved-objects-api-get.html) to retrieve the `index-pattern` saved object

Add your scripted field to `attributes. fields`. Fields is just a JSON array that has been serialized into a string for storage. Convert the string into JSON, add your scripted field to the array and then serialize back to a string.

Use the [saved object update API](https://www.elastic.co/guide/en/kibana/6.x/saved-objects-api-update.html) to update the `index-pattern` saved object.

---

<div class="post-metadata">

**Author:** ![sgarap](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@sgarap](https://discuss.elastic.co/u/sgarap)\
**Post date:** [July 11, 2018, 9:00am UTC](https://discuss.elastic.co/t/api-for-creating-scripted-fields/139236/3 "2018-07-11T09:00:10Z")

</div>

Hi Nathan,

I am using kibana 6.3.0 and my index patterns is '_ece_'.  
From the Dev Tools tab in Kibana I tried

> GET /api/saved\_objects/index-pattern/_ece_

This returned

> ```
> { "error": "no handler found for uri [/api/saved_objects/index-pattern/*ece*] and method [GET]"
> }
> 
> ```

Do I need to use any different id instead of _ece_? In Management tab \> Index Patterns, i have the name _ece_

---

<div class="post-metadata">

**Author:** ![Nathan\_Reese](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nathan_reese/32/84829_2.png) [@Nathan\_Reese](https://discuss.elastic.co/u/Nathan_Reese)\
**Post date:** [July 11, 2018, 1:03pm UTC](https://discuss.elastic.co/t/api-for-creating-scripted-fields/139236/4 "2018-07-11T13:03:21Z")

</div>

The Kibana dev tools can only be used for Elasticsearch APIs, meaning, it is a playground for interacting with Elasticsearch. Anything under `/api` is a Kibana API hosted by Kibana's web server.

The reason you are getting the error is that the GET request is getting passed to Elasticsearch which does not have a `/api/saved_objects` endpoint.

I would recommend using someting like [CURL](https://en.wikipedia.org/wiki/CURL) for interacting with Kibana's APIs.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 8, 2018, 1:03pm UTC](https://discuss.elastic.co/t/api-for-creating-scripted-fields/139236/5 "2018-08-08T13:03:23Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
