Is there an API example or blog that documents all...
# gooddata-cn
s
Is there an API example or blog that documents all the payload and API call details to create a dashboard and add an insight to it?
j
Hi Sheldon. I don’t think we have anything like that, but I’ll create an example for you.
I’m also making a note to create a community article that’d cover this.
The steps for creating a dashboard are complex and the UI clients abstracts away a lot of the work that goes on in the background. Missing a step or doing a step incorrectly creates a dashboard entity that can’t be accessed by the client. Creating them programmatically is likely to need a fair amount of work from your side. Nevertheless, here are the basic steps to create a working one. 1. Create an insight with POST to /api/v1/entities/workspaces/:workspaceId/visualizationObjects. Make sure to save its `"id"`:
Copy code
{
  "data": {
    "id": "TestInsight1",
    "type": "visualizationObject",
    "attributes": {
      "description": "",
      "content": {
        "buckets": [
          {
            "items": [
              {
                "attribute": {
                  "localIdentifier": "982a5e737fed4c7e8040884abf19412a",
                  "displayForm": {
                    "identifier": {
                      "id": "region",
                      "type": "label"
                    }
                  }
                }
              }
            ],
            "localIdentifier": "attribute"
          }
        ],
        "filters": [],
        "sorts": [
          {
            "attributeSortItem": {
              "attributeIdentifier": "982a5e737fed4c7e8040884abf19412a",
              "direction": "asc"
            }
          }
        ],
        "properties": {},
        "visualizationUrl": "local:table",
        "version": "2"
      },
      "title": "TestInsight1",
      "tags": []
    }
  }
}
2. Create a filter context with POST to /api/v1/entities/workspaces/:workspaceId/filterContexts (this is needed, as all dashboards contain at least the date filter). Make sure to save its `"id"`:
Copy code
{
  "data": {
    "id": "TestFilter1",
    "type": "filterContext",
    "attributes": {
      "content": {
        "filters": [
          {
            "dateFilter": {
              "from": "0",
              "to": "0",
              "granularity": "GDC.time.month",
              "type": "relative"
            }
          }
        ],
        "version": "2"
      },
      "title": "filterContext",
      "description": ""
    }
  }
}
3. Create the actual dashboard with POST to api/v1/entities/workspaces/:workspaceId/analyticalDashboards (embed the previously created insight and filter context by
"id"
inside the JSON structure):
Copy code
{
  "data": {
    "id": "TestDashboard1",
    "type": "analyticalDashboard",
    "attributes": {
      "content": {
        "filterContextRef": {
          "identifier": {
            "id": "TestFilter1",
            "type": "filterContext"
          }
        },
        "layout": {
          "type": "IDashboardLayout",
          "sections": [
            {
              "type": "IDashboardLayoutSection",
              "items": [
                {
                  "type": "IDashboardLayoutItem",
                  "size": {
                    "xl": {
                      "gridWidth": 6
                    }
                  },
                  "widget": {
                    "type": "insight",
                    "title": "TestInsight1",
                    "description": "",
                    "ignoreDashboardFilters": [],
                    "dateDataSet": {
                      "identifier": {
                        "id": "date",
                        "type": "dataset"
                      }
                    },
                    "insight": {
                      "identifier": {
                        "id": "TestInsight1",
                        "type": "visualizationObject"
                      }
                    },
                    "drills": [],
                    "properties": {}
                  }
                }
              ]
            }
          ]
        },
        "version": "2"
      },
      "title": "TestDashboard1",
      "description": ""
    }
  }
}
Is this helpful?
s
Thank you. I was able to create a dashboard that loaded correctly yesterday after providing values for the 'ignoreDashboardFilters', 'drills' and 'properties' attributes of the 'widget'. The problem really is that the 'dashboard->attributes->content' data is not documented at all.
j
I will submit that feedback to our doc team along with this community thread.
p
🎉 New note created.