# Try to add Visualization with Kibana API

**URL:** <https://discuss.elastic.co/t/try-to-add-visualization-with-kibana-api/198498>\
**Category:** Kibana\
**Created:** [September 7, 2019, 8:07am UTC](https://discuss.elastic.co/t/try-to-add-visualization-with-kibana-api/198498 "2019-09-07T08:07:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jsebrien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsebrien/32/27428_2.png) [@jsebrien](https://discuss.elastic.co/u/jsebrien)\
**Post date:** [September 7, 2019, 8:07am UTC](https://discuss.elastic.co/t/try-to-add-visualization-with-kibana-api/198498/1 "2019-09-07T08:07:11Z")

</div>

Hello,

I have some difficulties to add a new visualization with Kibana API.

I have the following pie.json:

```
{
"attributes": {
	"title": "[eCommerce] Sales by Gender2",
	"visState": "{  

```

"title":"[eCommerce] Sales by Gender2",  
"type":"pie",  
"params":{  
"type":"pie",  
"addTooltip":true,  
"addLegend":true,  
"legendPosition":"right",  
"isDonut":true,  
"labels":{  
"show":true,  
"values":true,  
"last\_level":true,  
"truncate":100  
}  
},  
"aggs":[  
{  
"id":"1",  
"enabled":true,  
"type":"count",  
"schema":"metric",  
"params":{

```
     }
  },
  {  
     \"id\":\"2\",
     \"enabled\":true,
     \"type\":\"terms\",
     \"schema\":\"segment\",
     \"params\":{  
        \"field\":\"customer_gender\",
        \"size\":5,
        \"order\":\"desc\",
        \"orderBy\":\"1\",
        \"otherBucket\":false,
        \"otherBucketLabel\":\"Other\",
        \"missingBucket\":false,
        \"missingBucketLabel\":\"Missing\"
     }
  }

```

]  
}",  
"uiStateJSON": "{}",  
"description": "",  
"version": 1,  
"kibanaSavedObjectMeta": {  
"searchSourceJSON": ""  
}  
}  
}

(which is an exact copy of [eCommerce] Sales by Gender - generated by Kibana wizard - except that the title is modified)

I'm executing this curl command:

curl -X POST -H 'Content-Type: application/json' -d '@pie.json' -H 'kbn-xsrf:true' [http://localhost:5601/api/saved\_objects/visualization](http://localhost:5601/api/saved_objects/visualization)

That returns :  
% Total % Received % Xferd Average Speed Time Time Time Current  
Dload Upload Total Spent Left Speed  
100 2488 100 1325 100 1163 3329 2922 --:--:-- --:--:-- --:--:-- 6251{"type":"visualization","id":"e1254720-d0b7-11e9-b4d8-fd6505e6383d","attributes":{"title":"[eCommerce] Sales by Gender2","visState":"{ "title":"[eCommerce] Sales by Gender2", "type":"pie", "params":{ "type":"pie", "addTooltip":true, "addLegend":true, "legendPosition":"right", "isDonut":true, "labels":{ "show":true, "values":true, "last\_level":true, "truncate":100 } }, "aggs":[{ "id":"1", "enabled":true, "type":"count", "schema":"metric", "params":{ } }, { "id":"2", "enabled":true, "type":"terms", "schema":"segment", "params":{ "field":"customer\_gender", "size":5, "order":"desc", "orderBy":"1", "otherBucket":false, "otherBucketLabel":"Other", "missingBucket":false, "missingBucketLabel":"Missing" } }]}","uiStateJSON":"{}","description":"","version":1,"kibanaSavedObjectMeta":{"searchSourceJSON":""}},"references":,"migrationVersion":{"visualization":"7.3.1"},"updated\_at":"2019-09-06T15:06:18.642Z","version":"WzM5LDVd"}

(which seems ok)

Then I try to display my new visualization:

 ![kibana](https://us1.discourse-cdn.com/elastic/original/3X/7/6/765f8b19de7ddc4c2f60ec2524887d25b05a3c23.jpeg)

But when I click on "[eCommerce] Sales by gender2", nothing happens. ( "whereas [eCommerce] Sales by gender" works)

I checked under Dev tools, i'm getting both visualizations (the original, and the one that I inserted):

# GET .kibana\_1/\_doc/visualization:ed8436b0-b88b-11e8-a6d9-e546fe2bba5f

{  
"\_index" : ".kibana\_1",  
"\_type" : "\_doc",  
"\_id" : "visualization:ed8436b0-b88b-11e8-a6d9-e546fe2bba5f",  
"\_version" : 1,  
"\_seq\_no" : 5,  
"\_primary\_term" : 1,  
"found" : true,  
"\_source" : {  
"visualization" : {  
"title" : "[eCommerce] Sales by Gender",  
"visState" : """{"title":"[eCommerce] Sales by Gender","type":"pie","params":{"type":"pie","addTooltip":true,"addLegend":true,"legendPosition":"right","isDonut":true,"labels":{"show":true,"values":true,"last\_level":true,"truncate":100}},"aggs":[{"id":"1","enabled":true,"type":"count","schema":"metric","params":{}},{"id":"2","enabled":true,"type":"terms","schema":"segment","params":{"field":"customer\_gender","size":5,"order":"desc","orderBy":"1","otherBucket":false,"otherBucketLabel":"Other","missingBucket":false,"missingBucketLabel":"Missing"}}]}""",  
"uiStateJSON" : "{}",  
"description" : "",  
"version" : 1,  
"kibanaSavedObjectMeta" : {  
"searchSourceJSON" : """{"query":{"query":"","language":"kuery"},"filter":,"indexRefName":"kibanaSavedObjectMeta.searchSourceJSON.index"}"""  
}  
},  
"type" : "visualization",  
"references" : [  
{  
"name" : "kibanaSavedObjectMeta.searchSourceJSON.index",  
"type" : "index-pattern",  
"id" : "ff959d40-b880-11e8-a6d9-e546fe2bba5f"  
}  
],  
"migrationVersion" : {  
"visualization" : "7.3.1"  
},  
"updated\_at" : "2019-09-04T15:37:51.641Z"  
}  
}

# GET .kibana\_1/\_doc/visualization:e1254720-d0b7-11e9-b4d8-fd6505e6383d

{  
"\_index" : ".kibana\_1",  
"\_type" : "\_doc",  
"\_id" : "visualization:e1254720-d0b7-11e9-b4d8-fd6505e6383d",  
"\_version" : 1,  
"\_seq\_no" : 39,  
"\_primary\_term" : 5,  
"found" : true,  
"\_source" : {  
"visualization" : {  
"title" : "[eCommerce] Sales by Gender2",  
"visState" : """{ "title":"[eCommerce] Sales by Gender2", "type":"pie", "params":{ "type":"pie", "addTooltip":true, "addLegend":true, "legendPosition":"right", "isDonut":true, "labels":{ "show":true, "values":true, "last\_level":true, "truncate":100 } }, "aggs":[{ "id":"1", "enabled":true, "type":"count", "schema":"metric", "params":{ } }, { "id":"2", "enabled":true, "type":"terms", "schema":"segment", "params":{ "field":"customer\_gender", "size":5, "order":"desc", "orderBy":"1", "otherBucket":false, "otherBucketLabel":"Other", "missingBucket":false, "missingBucketLabel":"Missing" } }]}""",  
"uiStateJSON" : "{}",  
"description" : "",  
"version" : 1,  
"kibanaSavedObjectMeta" : {  
"searchSourceJSON" : ""  
}  
},  
"type" : "visualization",  
"references" : ,  
"migrationVersion" : {  
"visualization" : "7.3.1"  
},  
"updated\_at" : "2019-09-06T15:06:18.642Z"  
}  
}

Mine does not have any references, and other tags are empty (those tags being "outside" the attributes block)? Does this explain why I cannot display my visualization? How can i modify my json to make it work? Do I have to insert a new index template and link to it to make the whole thing work?

Regards,

Julien

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [September 13, 2019, 10:27am UTC](https://discuss.elastic.co/t/try-to-add-visualization-with-kibana-api/198498/2 "2019-09-13T10:27:45Z")

</div>

A visualization object will need to point to an index pattern, hence the reference to that index pattern. If that is missing the object will not work, so that is what you need to add to your visualization:  
"type" : "visualization",  
"references" : [  
{  
"name" : "kibanaSavedObjectMeta.searchSourceJSON.index",  
"type" : "index-pattern",  
"id" : "ff959d40-b880-11e8-a6d9-e546fe2bba5f"  
}

---

<div class="post-metadata">

**Author:** ![jsebrien](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsebrien/32/27428_2.png) [@jsebrien](https://discuss.elastic.co/u/jsebrien)\
**Post date:** [September 23, 2019, 6:14pm UTC](https://discuss.elastic.co/t/try-to-add-visualization-with-kibana-api/198498/3 "2019-09-23T18:14:34Z")

</div>

Thanks, it worked indeed.  
Regards,  
Julien

---

<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 21, 2019, 6:14pm UTC](https://discuss.elastic.co/t/try-to-add-visualization-with-kibana-api/198498/4 "2019-10-21T18:14:37Z")

</div>

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