Kibana: add object to existing dashboard

I am developing a set of scripts to manage Kibana objects, I have created an object and created a dashboard ( with some initial list of objects in it) and now I would like to place/add my new object in this existing dashboard.

I have extracted dashboard JSON and extracted the id of my visualization object. Then I update "references" in dashboard_json with a dictionary: {'name': 'panel_new', 'type': 'visualization', 'id': 'd4ef9b30-2ab2-11eb-b19d-9b0fdf84f862'}

and then I add into dashboard_json['attributes']['panelsJSON'] next dictionary {"panelRefName": "panel_new"}

but it makes my dashboard is broken ( Kibana shows empty white page instead of the dashboard) As I see all existing objects in my dashboard in dashboard_json['attributes']['panelsJSON'] has coordinates of object position in the dashboard. Should I add it also? how can I calculate it? What should I do more to correct add the object into my dashboard? How it can be done at all?

Hi @Eugene_Dobrovolskyi

If you open your browser's Developer Tools, you'll notice the console shows an error panelNew.gridData is undefined. This means gridData is required in the panelsJSON documents.
The gridData has:

  • the x and y values: if not provided it will be appended in a new row at the end of the dashboard.
  • the w and h values: the width and height of the panel containing your visualization
  • i: it should match panelIndex and it's a unique identifier of this entry.

In order to calculate the positioning, you can look for the document with the max values of x and y (let's call them x0 and y0). Your new x will be x0 + w0 (from the previous doc) and y will match the y0 from that doc as well.
If your new x plus the w of your viz will be higher than the max-width of your dashboard (typically 48), you should use x = 0 and y = y0 + h0.

  {
    "version": "7.10.0",
    "gridData": {
      "x": 24,
      "y": 100,
      "w": 24,
      "h": 15,
      "i": "any-random-value"
    },
    "panelIndex": "any-random-value",
    "panelRefName": "panel_new"
  }

Please, bear in mind this might change in future versions and overwriting saved objects should be done with caution.

Hi @afharo
many thanks for your answer!
it helped me!

1 Like

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