โ02-16-2024 12:50 PM - edited โ02-16-2024 12:50 PM
I'm trying to import a Lakeview Dashboard that I've originally exported through the CLI (version 0.213.0). The exported file has extension .lvdash.json and is a single line json file.
I can't get it to work, I tried this command:
databricks workspace import /Users/my@user.com/my_first_lakeview_dashboard.lvdash.json --profile prd --file dashboard.json
but I get: "Error: The zip file may not be valid or may be an unsupported version. Hint: Objects imported using format=SOURCE are expected to be zip encoded databricks source notebook(s) by default. Please specify a language using the --language flag if you are trying to import a single uncompressed notebook"
There is a language flag but the only options available are: [PYTHON, R, SCALA, SQL].
There is json flag but it's only for providing the request in JSON format.
There is no mention of Lakeview dashboards in this API. Is this even supported? Or do I have the syntax wrong? The Lakeview API only supports publishing.
โ05-29-2024 08:17 PM
Turns out the problem was between keyboard and chair! The issues was with using requests data vs json. Here's the full working code:
โ02-17-2024 03:22 PM
Thanks for flagging. There should be enhanced API documentation specific to Lakeview in the next week or two (PR is in review). Keep an eye out for a page called "Use the Lakeview API and Workspace API to create and manage Lakeview dashboards."
Currently, there is API support for Lakeview dashboard:
Additional areas are under development.
For a bit more information on Lakeview dashboard export/import via API specifically....
If we want to export the contents of mydashboard.lvdash.json, we can use the Workspace Export API to do so.
GET /api/2.0/workspace/export
Query parameters:
{
"path": "/Users/my@user.com/examples/mydashboard.lvdash.json",
"direct_download": true
}
Response:
{
"pages": [
{
"name": "7db2d3cf",
"displayName": "New Page"
}
]
}
This response shows the contents of a minimal dashboard definition which is blank.
Note that the file name without extension is what appears as the name of the dashboard in the Workspace (mydashboard.lvdash.json). If the direct_download property is left out of the request or is set to false, the response will include the base64 encoded version of the json string. We will use this later for the import request.
GET /api/2.0/workspace/export
Query parameters:
{
"path": "/Users/my@user.com/examples/mydashboard.lvdash.json",
"direct_download": false
}
Response:
{
"content": "eyJwYWdlcyI6W3sibmFtZSI6IjdkYjJkM2NmIiwiZGlzcGxheU5hbWUiOiJOZXcgUGFnZSJ9XX0=",
"file_type": "lvdash.json"
}
If we want to import another dashboard into the workspace using the same contents as mydashboard.lvdash.json, we can do so by using the Workspace Import API. For the import to be properly recognized as a Lakeview dashboard, a few important parameters must be set:
If these settings are not configured properly, the import might succeed but the dashboard would be treated like a normal file.
POST /api/2.0/workspace/import
Request body parameters:
{
"path": "/Users/my@user.com/examples/myseconddashboard.lvdash.json",
"content": "eyJwYWdlcyI6W3sibmFtZSI6IjdkYjJkM2NmIiwiZGlzcGxheU5hbWUiOiJOZXcgUGFnZSJ9XX0=",
"format": "AUTO"
}
Response:
{}
If we were to immediately issue the same API request, we would get an error:
{
"error_code": "RESOURCE_ALREADY_EXISTS",
"message": "Path (/Users/my@user.com/examples/myseconddashboard.lvdash.json) already exists."
}
In order to overwrite the contents of an existing dashboard in place, the "overwrite" property can be set:
POST /api/2.0/workspace/import
Request body parameters:
{
"path": "/Users/my@user.com/examples/myseconddashboard.lvdash.json",
"content": "eyJwYWdlcyI6W3sibmFtZSI6IjdkYjJkM2NmIiwiZGlzcGxheU5hbWUiOiJOZXcgUGFnZSJ9XX0=",
"format": "AUTO",
"overwrite": true
}
Response:
{}
โ05-29-2024 02:04 PM
Thanks for the very detailed response. This is a fantastic example of a detailed support response.
We have a problem with the import API. No matter the combination of content parameter (base64, pure JSON, json dump, str, etc.) the API always returns
b'{"error_code":"MALFORMED_REQUEST","message":"Invalid JSON given in the body of the request - failed to parse given JSON"}\n'
Here's the code we're using: iterate over all our warehouses and create a dashboard for each. The JSON dashboard file is taken straight from
Has there been an update to the API to make Lakeview Dashboards work more smoothly?
โ05-29-2024 08:17 PM
Turns out the problem was between keyboard and chair! The issues was with using requests data vs json. Here's the full working code:
โ05-30-2024 06:23 AM
Glad you've got everything up and running!
Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโt want to miss the chance to attend and share knowledge.
If there isnโt a group near you, start one and help create a community that brings people together.
Request a New Group