Create a dashboard using REST API endpoints

Create or replicate dashboards from different environments using the data/ui/views REST API endpoint. For example, you can move a dashboard from a testing environment to production with the REST API endpoint. The REST API endpoints can also read, update, and delete dashboards.

Format the dashboard definition

When creating a dashboard using REST API endpoints, the components of a dashboard definition must follow a specific format.

Root node

The root node must be <dashboard version="2">, which indicates the dashboard is a Studio dashboard. You can also specify the theme as "light" or "dark" with the theme attribute in the root node. The following is an example of a root node.

<dashboard version="2" theme="dark">

Hidden elements

Hide different UI elements in View mode with hiddenElements. hiddenElements is an attribute of the root node.

  • Set hideEdit to "true" to hide the Edit button.
  • Set hideOpenInSearch to "true" to remove the ability to open and edit a query in the full Search experience.
  • Set hideExport to "true" to remove the ability to export dashboards.

The following is a hidden element example.

<dashboard version="2" theme="light" hiddenElements="{&quot;hideEdit&quot;:false,&quot;hideOpenInSearch&quot;:false,&quot;hideExport&quot;:false}">

Label

Title your dashboard with the label. The following is an example of a label.

<label>Sample Dashboard</label>

Description

Provide extra context about your dashboard with the description. The following is an example of a description.

<description>Sample Description</description>

Definition

The dashboard's JSON definition must be wrapped in <![CDATA[ … ]]>. If you save the dashboard with the UI instead of the API, any indenting or formatting in the JSON will be stripped. The following is an example of how a <![CDATA[ … ]]> wraps around a dashboard JSON definition.

 <definition><![CDATA[
  {
    <JSON definition here>
  }
 ]]></definition>

Create a dashboard

You can create a dashboard with the following steps.

  1. Write your initial REST command. The command uses the following structure: https://<host>:<mPort>/servicesNS/{user}/{app_name}/data/ui/views. For example, your REST command might look like the following:
    curl -k -u admin:pass https://localhost:8089/servicesNS/admin/search/data/ui/views \
    
  2. Write your header request parameter. For example, your header request parameter might look like the following:
    --header 'Content-Type: application/x-www-form-urlencoded' \
    
  3. Write the name data request parameter with the ID of your dashboard. For example, your request parameter might look like the following:
    --data-urlencode 'name=sample_dashboard' \
    
  4. Write the eai:data data request parameter. For example, your request parameter might look like the following:
    --data-urlencode 'eai:data=
    <dashboard version="2" theme="dark">
    

Example of creating a dashboard using REST API endpoints

The following example shows how to create a dashboard using the /data/ui/views endpoint.

curl -k -u admin:pass https://localhost:8089/servicesNS/admin/search/data/ui/views \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'name=sample_dashboard' \
--data-urlencode 'eai:data=
       <dashboard version="2" theme="light" hiddenElements="{&quot;hideEdit&quot;:false,&quot;hideOpenInSearch&quot;:false,&quot;hideExport&quot;:false}">
           <label>Sample Dashboard</label>
           <description></description>
           <definition><![CDATA[{"visualizations":{},"dataSources":{},"defaults":{"dataSources":{"ds.search":{"options":{"queryParameters":{"latest":"$global_time.latest$","earliest":"$global_time.earliest$"}}}}},"inputs":{"input_global_trp":{"type":"input.timerange","options":{"token":"global_time","defaultValue":"-24h@h,now"},"title":"Global Time Range"}},"layout":{"type":"absolute","options":{"display":"auto-scale"},"structure":[],"globalInputs":["input_global_trp"]},"description":"","title":"Sample Dashboard"}]]></definition>
       </dashboard>'

Reading, updating, and deleting a dashboard

You can pull, update, and delete your dashboard using GET, POST, and DELETE HTTP methods. For more details, see data/ui/views/{name} in the REST API Reference manual.