How to Export Dashboard using API

Related Tags: integration dashboard

Everything you can do over the UI can be also done via our API. So you can export the dashboard programatically. To export the Dashboard, you have to follow several steps:

  1. Get the report execution context (filters)
  2. Execute the dashboard with given context
  3. Call Dashboard export
  4. Download the dashboard

GET Filter URI

First of all you need to get all filters that are used on the Dashboard.

Find the list of dashboards by calling GET to the following resource:

https://secure.gooddata.com/gdc/md/{project-id}/query/projectdashboards

You can easily find the single dashboard you want to export, get the dashboard definition and extract used dashboard filters from it. See the JSON below, it is the dashboard object.

….
       ….
          }
               ]
            }
         ],
         "filters" : [
            {
               "filterItemContent" : {
                  "obj" : "/gdc/md/{project-id}/obj/69",
                  "multiple" : 1,
                  "default" : {
                     "to" : 0,
                     "from" : -1050,
                     "type" : "floating"
                  },
                  "type" : "time",
                  "label" : null,
                  "id" : "fr-yui_3_14_1_1_1401371695372_25558"
               }
            },
            {
               "filterItemContent" : {
                  "obj" : "/gdc/md/{project-id}/obj/213",
                  "multiple" : 1,
                  "type" : "list",
                  "label" : null,
                  "id" : "fr-yui_3_14_1_1_1401371695372_31948"
               }
            }
         ]
      },
      "meta" : {
         "author" : "/gdc/account/profile/2f35048619b7b0ff03f408d2c4b6390d",
         "uri" : "/gdc/md/{project-id}/obj/259",
         "tags" : "",
    ….
….

Execute the dashboard with context

You need to have “execution context” that means all filters that affects the dashboard. Use following resource and POST all filters to get the execution context.

https://secure.gooddata.com/gdc/internal/projects/lwcwv545ddbmx0ki3p50mxfmpr6e4o7b/executionContexts

Body:

{
    "executionContext": {
        "filters": [
            {
                "uri": "/gdc/md/{project-id}/obj/213",
                "id": "fr-yui_3_14_1_1_1401371695372_31948"
            }
        ],
        "dashboard": "/gdc/md/{project-id}/obj/259",
        "type": "export"
    }
}

Response:

201 Created

{
    "uri": "/gdc/internal/projects/{project-id}/executionContexts/tmp538d8697e4b0413b989bca6d"
}

Export the Dashboard

Use client export API to export the Dashboard. Call the following resource:

https://secure.gooddata.com/gdc/projects/{project-id}/clientexport

REQUEST:

{
    "clientExport": {
        "url": "https://secure.gooddata.com/dashboard.html#project=/gdc/projects/{project-id}&dashboard=/gdc/md/{project-id}/obj/259&tab=9835f55191d6&export=1&ctx=/gdc/internal/projects/{project-id}/executionContexts/tmp538d82f6e4b0413b989bca66",
        "name": "Dashboard"
    }
}

RESPONSE:

{
    "asyncTask": {
        "link": {
            "poll": "/gdc/projects/{project-id}/clientexport/14645cc1b0a5d7fcefa14b588885dd2200000027"
        }
    }
}

Poll the URL from response Result:

GET:

https://secure.gooddata.com/gdc/projects/{project-id}/clientexport/89f74636f1039583e8de6a9e3e6740ec00000027

Once export is ready, you get the 200 OK response and you must call GET

https://secure.gooddata.com/gdc/projects/{project-id}/clientexport/89f74636f1039583e8de6a9e3e6740ec00000027?download=true

Now, Save the PDF and you are all set.