# Creating Index Patterns and Dashboards Using API

**URL:** https://discuss.elastic.co/t/creating-index-patterns-and-dashboards-using-api/309548
**Category:** Kibana
**Created:** [July 13, 2022, 3:21pm UTC](https://discuss.elastic.co/t/creating-index-patterns-and-dashboards-using-api/309548 "2022-07-13T15:21:16Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![christng](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@christng](https://discuss.elastic.co/u/christng)
#### Post date: [July 13, 2022, 3:21pm UTC](https://discuss.elastic.co/t/creating-index-patterns-and-dashboards-using-api/309548/1 "2022-07-13T15:21:16Z")

</div>

I'm using Kubernetes and trying to create index patterns and dashboards on Kibana 7.17 using the curl commands but they do not seem to be working. I've followed everything at these sources: [Saved objects APIs | Kibana Guide [7.17] | Elastic](https://www.elastic.co/guide/en/kibana/7.17/saved-objects-api.html) and [Index patterns APIs | Kibana Guide [7.17] | Elastic](https://www.elastic.co/guide/en/kibana/7.17/index-patterns-api.html) but nothing has worked.

Currently, I have this command:  
curl "-XPOST" "/api/index\_patterns/filebeat" "-H 'Content-Type: application/json' -d '{"attributes": {"title": "filebeat\*", "timeFieldName": "@timestamp"}}'"

Can someone help with this?

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [July 13, 2022, 3:25pm UTC](https://discuss.elastic.co/t/creating-index-patterns-and-dashboards-using-api/309548/2 "2022-07-13T15:25:11Z")

</div>

Hi @christng

Think you need to look at this page you are missing some of the headers etc.  
2nd always helpful to show the response error etc.. otherwise we are just guessing  
3rd I assume you are actually putting the host and port into the API call.

> **[REST API | Kibana Guide \[7.17\] | Elastic](https://www.elastic.co/guide/en/kibana/7.17/api.html)**
>
> Kibana provides you with several options to share \*Discover\* saved searches, dashboards, \*Visualize Library\* visualizations, and \*Canvas\* workpads with others, or on a website.

Example

```auto
curl -X POST \
  http://localhost:5601/api/spaces/space \
  -H 'Content-Type: application/json' \
  -H 'kbn-xsrf: true' \
  -d '{
	"id": "sales",
	"name": "Sales",
	"description": "This is your Sales Space!",
	"disabledFeatures": []
}
'

```

---

<div class="post-metadata">

### Author: ![christng](https://avatars.discourse-cdn.com/v4/letter/c/f19dbf/32.png) [@christng](https://discuss.elastic.co/u/christng)
#### Post date: [July 13, 2022, 3:41pm UTC](https://discuss.elastic.co/t/creating-index-patterns-and-dashboards-using-api/309548/3 "2022-07-13T15:41:29Z")

</div>

Thank you for your response. Currently, the helm chart I'm using has this command which successfully creates the watcher index pattern:

run\_elastic\_curl "-XPOST" "/api/saved\_objects/\_import" "@/etc/watcherConfig/watcher-index-pattern.ndjson"

But when I add my own command:  
run\_elastic\_curl "-XPOST" "/api/index\_patterns/filebeat" "-H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d '{"attributes": {"title": "filebeat\*", "timeFieldName": "@timestamp"}}'"

I get this error:  
FAILED with response [{"statusCode":404,"error":"Not Found","message":"Not Found"}404]

Am I missing something?

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [July 13, 2022, 4:54pm UTC](https://discuss.elastic.co/t/creating-index-patterns-and-dashboards-using-api/309548/4 "2022-07-13T16:54:40Z")

</div>

Hi @christng

I am not familiar with `run_elastic_curl`

However you do not have correct syntax for the create index pattern body see [here](https://www.elastic.co/guide/en/kibana/7.17/index-patterns-api-create.html)

You have an `attributes` top field etc... not correct.

Here is a working version

```auto
curl --location --request POST 'http://localhost:5601/api/index_patterns/index_pattern' \
--header 'Content-Type: application/json' \
--header 'kbn-xsrf: true' \
--data-raw '{
    "override":false,
    "refresh_fields":true,
    "index_pattern":{
        "title": "test",
        "timeFieldName": "@timestamp"
    }
}'

```

or shorthand

```auto
curl -X POST 'http://localhost:5601/api/index_patterns/index_pattern' \
-H 'Content-Type: application/json' \
-H 'kbn-xsrf: true' \
-d '{
    "override":false,
    "refresh_fields":true,
    "index_pattern":{
        "title": "test-3",
        "timeFieldName": "@timestamp"
    }
}'

```

---

<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 10, 2022, 4:55pm UTC](https://discuss.elastic.co/t/creating-index-patterns-and-dashboards-using-api/309548/5 "2022-08-10T16:55:03Z")

</div>

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