Preview dashboard chart SQL¶
Execute a chart SQL preview, returning query results without saving the chart.
POST https://api.moi.matrixorigin.cn/v5/data-dashboards/{dashboard_id}/preview
Preparation before calling¶
Prepare a personal access token and target workspace ID that has access to the target workspace.
The example below uses:
$AI_STUDIO_API_KEY: The actual personal access token, passed through theX-API-KeyHeader.$WORKSPACE_ID: Target workspace ID, passed throughX-Workspace-IDHeader.$DASHBOARD_ID:dashboard_idto use, specifying the target resource via the request path.
Request body¶
Replace caller-specific values in the example with actual values.
sql_textstringRequired- The SQL to preview.
Request example
curl -X POST "https://api.moi.matrixorigin.cn/v5/data-dashboards/$DASHBOARD_ID/preview" \
-H "X-API-Key: $AI_STUDIO_API_KEY" \
-H "X-Workspace-ID: $WORKSPACE_ID" \
-H "Content-Type: application/json" \
-d '{
"sql_text": "SELECT 1 AS value"
}'
Successful response¶
The endpoint executes SQL synchronously and returns up to 1,000 rows. truncated: true indicates that more rows exist beyond this limit.
{
"code": "OK",
"msg": "OK",
"data": {
"query_id": "query-001",
"db_name": "analytics",
"statement_id": "stmt-001",
"status": "success",
"limit": 1000,
"total": 1,
"columns": [
{
"name": "value",
"type": "BIGINT"
}
],
"result": [
[{"String": "1", "Valid": true}]
],
"elapsed_ms": 12,
"truncated": false
}
}
The response fields are as follows.
Field |
Type |
Description |
|---|---|---|
|
string |
|
|
string |
|
|
string |
Query ID. |
|
string |
Database used to execute the SQL. |
|
string |
Statement ID. |
|
string |
Query status. |
|
string |
Error message, returned when the query fails. |
|
integer |
Result offset; currently zero and omitted when zero. |
|
integer |
Maximum rows in this preview, currently 1,000. |
|
integer |
Number of rows returned, up to 1,000. |
|
integer |
Preview duration in milliseconds. |
|
boolean |
Whether additional rows exceed the 1,000-row limit. |
|
array |
Result column. |
|
string |
Column name. |
|
string |
Column type. |
|
array |
Result data. |
|
string |
Cell value as a string. |
|
boolean |
Whether the cell has a value; false indicates null. |
|
string |
Message returned when a statement has no result set. |
Error response¶
This example corresponds to HTTP 400.
codestring- Error code, such as ErrParamInvalid or ErrDataDashboardNotFound.
msgstring- HTTP status text, such as Bad Request or Not Found.
{
"code": "ErrParamInvalid",
"msg": "Bad Request"
}