# Saved Objects imported via Kibana API do not display

**URL:** <https://discuss.elastic.co/t/saved-objects-imported-via-kibana-api-do-not-display/283889>\
**Category:** Kibana\
**Created:** [September 10, 2021, 1:37pm UTC](https://discuss.elastic.co/t/saved-objects-imported-via-kibana-api-do-not-display/283889 "2021-09-10T13:37:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pheathers](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@pheathers](https://discuss.elastic.co/u/pheathers)\
**Post date:** [September 10, 2021, 1:37pm UTC](https://discuss.elastic.co/t/saved-objects-imported-via-kibana-api-do-not-display/283889/1 "2021-09-10T13:37:41Z")

</div>

I have been working to script the import of an index pattern with a fields. The import appears to run successfully, but when I try to display the imported index pattern under Kibana | Index Patterns, it fails to load. All I see is a blank screen.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/6/a6bfb3812e2c1ebc2388e2226699f63cbf94597e.png)

I'm using the following PowerShell script to create the index pattern

```auto
$url = "http://localhost:5601/api/saved_objects/index-pattern/my-pattern";

$body = @"
{
    "attributes": {
        "title": "my-pattern-*",
        "timeFieldName": "@timestamp",
        "fields": [
            {
		        "name": "field1",
		        "type": "string",
		        "count": 0,
		        "scripted": false,
		        "searchable": true,
		        "aggregatable": false,
		        "readFromDocValues": false
	        }
        ]
    }
}
"@;

$params = @{
    Uri = $url;
    Method = 'POST';
    Headers = @{ 'kbn-xsrf' = "true" }
    ContentType = 'application/json';
};

$Result = Invoke-WebRequest @params -Body $body;
Write-Host $Result.StatusCode;
Write-Host $Result;

```

I receive an HTTP 200 response with the following JSON

```auto
{
	"type": "index-pattern",
	"id": "my-pattern",
	"attributes": {
		"title": "my-pattern-*",
		"timeFieldName": "@timestamp",
		"fields": [
			{
				"name": "field1",
				"type": "string",
				"count": 0,
				"scripted": false,
				"searchable": true,
				"aggregatable": false,
				"readFromDocValues": false
			}
		]
	},
	"references": [],
	"migrationVersion": {
		"index-pattern": "7.11.0"
	},
	"coreMigrationVersion": "7.12.0",
	"updated_at": "2021-09-10T13:31:54.118Z",
	"version": "WzE4NDcsMTFd",
	"namespaces": [
		"default"
	]
}

```

I can then see the new index pattern under Kibana | Index Patterns or under Kibana | Saved Objects. However, when I try to view the Index Pattern, it fails to load. The browser Dev Tools | Console shows the following message

```auto
Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse (<anonymous>)
    at index_patterns_IndexPatternsService.savedObjectToSpec (data.plugin.js:1)
    at index_patterns_IndexPatternsService.getSavedObjectAndInit (data.plugin.js:1)

```

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/f/af2905b1d2a8b032a9f8e50fc5c0f8619a4ad06f.png)

If I look at the Dev Tools | Network, I can see that Kibana is making a request for the data of the index pattern and it returns JSON in the **\_bulk\_get** request. It is immediately after this request that the error displays.

```auto
{
	"saved_objects": [
		{
			"id": "my-pattern",
			"type": "index-pattern",
			"namespaces": [
				"default"
			],
			"updated_at": "2021-09-10T13:31:54.118Z",
			"version": "WzE4NDcsMTFd",
			"attributes": {
				"title": "my-pattern-*",
				"timeFieldName": "@timestamp",
				"fields": [
					{
						"name": "field1",
						"type": "string",
						"count": 0,
						"scripted": false,
						"searchable": true,
						"aggregatable": false,
						"readFromDocValues": false
					}
				]
			},
			"references": [],
			"migrationVersion": {
				"index-pattern": "7.11.0"
			},
			"coreMigrationVersion": "7.12.0"
		}
	]
}

```

If I import the index pattern without the _fields_ attribute, it imports successfully.

Any thoughts on what's wrong?

---

<div class="post-metadata">

**Author:** ![pheathers](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@pheathers](https://discuss.elastic.co/u/pheathers)\
**Post date:** [September 10, 2021, 2:00pm UTC](https://discuss.elastic.co/t/saved-objects-imported-via-kibana-api-do-not-display/283889/2 "2021-09-10T14:00:54Z")

</div>

My example above created an index pattern (my-pattern), but the index pattern didn't match any indexes. When I created an index pattern which matched existing indexes, I was able to create the index pattern via the Kibana API, however I didn't include any fields (note, dclogstash-troubleshooting is the name of my index)

```auto
$url = "http://localhost:5601/api/saved_objects/index-pattern/dclogstash";

$body = @"
{
    "attributes": {
        "title": "dclogstash-*",
        "timeFieldName": "@timestamp"
    }
}
"@;

$params = @{
    Uri = $url;
    Method = 'POST';
    Headers = @{ 'kbn-xsrf' = "true" }
    ContentType = 'application/json';
};

$Result = Invoke-WebRequest @params -Body $body;
Write-Host $Result.StatusCode;
Write-Host $Result;

```

When I did this all of the fields associated with the index appeared in the index pattern.

---

<div class="post-metadata">

**Author:** ![mattkime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattkime/32/43522_2.png) [@mattkime](https://discuss.elastic.co/u/mattkime)\
**Post date:** [September 10, 2021, 8:00pm UTC](https://discuss.elastic.co/t/saved-objects-imported-via-kibana-api-do-not-display/283889/3 "2021-09-10T20:00:17Z")

</div>

@pheathers What version of the elastic stack are you using? Its possible that there's a better API for your needs - [Create index pattern API | Kibana Guide [7.14] | Elastic](https://www.elastic.co/guide/en/kibana/current/index-patterns-api-create.html)

Note that you shouldn't need to 'refreshFields' unless you need to see the field list in the response.

---

<div class="post-metadata">

**Author:** ![pheathers](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@pheathers](https://discuss.elastic.co/u/pheathers)\
**Post date:** [September 10, 2021, 8:39pm UTC](https://discuss.elastic.co/t/saved-objects-imported-via-kibana-api-do-not-display/283889/4 "2021-09-10T20:39:22Z")

</div>

Hi @mattkime . I'm using Kibana 7.12.

What I noticed is that if I don't include the fields and the newly created index pattern has a match for an existing index, all of the fields show in the index pattern.

---

<div class="post-metadata">

**Author:** ![mattkime](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattkime/32/43522_2.png) [@mattkime](https://discuss.elastic.co/u/mattkime)\
**Post date:** [September 10, 2021, 8:49pm UTC](https://discuss.elastic.co/t/saved-objects-imported-via-kibana-api-do-not-display/283889/5 "2021-09-10T20:49:42Z")

</div>

@pheathers Yes, that is correct. Are you trying to modify the field list in some manner?

---

<div class="post-metadata">

**Author:** ![pheathers](https://avatars.discourse-cdn.com/v4/letter/p/67e7ee/32.png) [@pheathers](https://discuss.elastic.co/u/pheathers)\
**Post date:** [September 10, 2021, 9:29pm UTC](https://discuss.elastic.co/t/saved-objects-imported-via-kibana-api-do-not-display/283889/6 "2021-09-10T21:29:57Z")

</div>

Yes, and likely incorrectly. I _thought_ that I would be able to create the index pattern and all of the fields manually, but what I learned is that I only have to create the index pattern and associate with existing indexes.

That is all I needed. I appreciate the help.

---

<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:** [October 8, 2021, 9:30pm UTC](https://discuss.elastic.co/t/saved-objects-imported-via-kibana-api-do-not-display/283889/7 "2021-10-08T21:30:33Z")

</div>

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