Generate dashboard chart SQL draft

Generate read-only SQL drafts and suggested chart types available for the current data dashboard based on natural language questions. The interface only generates and verifies drafts, does not execute SQL, and does not create Kanban charts.

HTTP
POST $CLOUDSIGMA_API_BASE/data-dashboards/{dashboard_id}/generate-sql

Before you call

Configure the CloudSigma regional endpoint and authentication before calling. The endpoint, credentials, workspace, and resource IDs must belong to the same region. First select the data dashboard that has configured database and data table in Query Data Kanban List.

Prepare personal access token and target workspace ID that can access the target workspace.

Request body

Replace $DASHBOARD_ID, $CLOUDSIGMA_API_KEY, $WORKSPACE_ID in the example with actual values.

Shell
curl -X POST "$CLOUDSIGMA_API_BASE/data-dashboards/$DASHBOARD_ID/generate-sql" \
  -H "X-API-Key: $CLOUDSIGMA_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{
  "question": "统计最近 30 天每天的销售额",
  "title": "近 30 天销售趋势"
}'

Parameter

Type

Required

Description

dashboard_id

string

Yes

Data dashboard ID.

Request body

Field

Type

Required

Description

question

string

Yes

The question you want to answer through data cannot be empty.

title

string

No

Chart title, used to assist in generating drafts.

Successful response

JSON
{
  "code": "OK",
  "msg": "OK",
  "data": {
    "sql_text": "SELECT sale_date, SUM(amount) AS total_amount FROM sales WHERE sale_date >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY) GROUP BY sale_date ORDER BY sale_date",
    "chart_type": "line"
  }
}

Field

Type

Description

data.sql_text

string

Generate and verify a read-only SQL draft.

data.chart_type

string

Recommended chart types. Values: metric, table, line, bar, pie, area, combo, stacked_bar, scatter.

Error response

JSON
{
  "code": "ErrDataDashboardSQLDraftValidationFailed",
  "message": "生成的 SQL 未通过校验"
}

Field

Type

Description

code

integer or string

Error code or status code.

message

string

error message.

Last updated on