The Dataset API allows you to execute ad-hoc queries and retrieve data. This is the primary endpoint for running queries programmatically. The API includes 8 endpoints.
Execute query
Execute an ad-hoc query and retrieve results.
curl -X POST \
https://your-metabase.com/api/dataset \
-H 'Content-Type: application/json' \
-H 'X-Metabase-Session: SESSION_TOKEN' \
-d '{
"database": 1,
"type": "query",
"query": {
"source-table": 5,
"limit": 10
}
}'
Request body
Database ID to query (optional for saved question queries)
Query type: “query” (MBQL) or “native” (SQL)
MBQL query objectExample MBQL query:{
"source-table": 5,
"aggregation": [["count"]],
"breakout": [["field", 12, null]],
"limit": 100
}
Native SQL query (when type is “native”)Example:{
"query": "SELECT * FROM orders LIMIT 100",
"template-tags": {}
}
Parameter values for template tags
Query constraints like max results
Response
Query results
rows - Array of result rows
cols - Array of column metadata
rows_truncated - Number of rows truncated (if limited)
Database that was queried
Query status: “completed”, “failed”, etc.
Query execution time in milliseconds
The query that was executed
{
"data": {
"rows": [
[1, "Product A", 29.99],
[2, "Product B", 49.99]
],
"cols": [
{
"name": "ID",
"base_type": "type/Integer",
"display_name": "ID"
},
{
"name": "NAME",
"base_type": "type/Text",
"display_name": "Name"
},
{
"name": "PRICE",
"base_type": "type/Float",
"display_name": "Price"
}
]
},
"status": "completed",
"row_count": 2,
"running_time": 145
}
This endpoint does not use query caching. Results are always fresh from the database.
Export query results
Execute a query and download results in a specific format.
POST /api/dataset/{export-format}
curl -X POST \
https://your-metabase.com/api/dataset/csv \
-H 'Content-Type: application/json' \
-H 'X-Metabase-Session: SESSION_TOKEN' \
-d '{
"query": {
"database": 1,
"type": "query",
"query": {
"source-table": 5
}
},
"visualization_settings": {},
"format_rows": true,
"pivot_results": false
}' \
-o results.csv
Parameters
Export format: csv, xlsx, or json
Request body
Query object with database, type, and query/native fields
Visualization settings (can be empty object)
Apply cell formatting to values (default: false)
Pivot the results (default: false)
Response
Returns file data with appropriate content-type:
- CSV:
text/csv
- XLSX:
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
- JSON:
application/json
Get metadata needed to construct a query.
POST /api/dataset/query_metadata
curl -X POST \
https://your-metabase.com/api/dataset/query_metadata \
-H 'Content-Type: application/json' \
-H 'X-Metabase-Session: SESSION_TOKEN' \
-d '{
"database": 1
}'
Request body
Database ID to get metadata for
Response
Returns database metadata including tables, fields, and foreign key relationships needed for building queries.
Convert to native query
Convert an MBQL query to native SQL.
curl -X POST \
https://your-metabase.com/api/dataset/native \
-H 'Content-Type: application/json' \
-H 'X-Metabase-Session: SESSION_TOKEN' \
-d '{
"database": 1,
"type": "query",
"query": {
"source-table": 5,
"limit": 10
},
"pretty": true
}'
Request body
Format the SQL with indentation (default: true)
Response
{
"query": "SELECT * FROM orders LIMIT 10"
}
Get parameter values
Get possible values for a query parameter.
POST /api/dataset/parameter/values
curl -X POST \
https://your-metabase.com/api/dataset/parameter/values \
-H 'Content-Type: application/json' \
-H 'X-Metabase-Session: SESSION_TOKEN' \
-d '{
"parameter": {
"id": "param1",
"type": "category",
"target": ["dimension", ["field", 5, null]]
},
"field_ids": [5]
}'
Request body
Parameter definition with id, type, and target
Field IDs to get values from
Response
Returns an array of possible parameter values.
Search parameter values
Search for parameter values matching a query string.
POST /api/dataset/parameter/search/{query}
curl -X POST \
https://your-metabase.com/api/dataset/parameter/search/electronics \
-H 'Content-Type: application/json' \
-H 'X-Metabase-Session: SESSION_TOKEN' \
-d '{
"parameter": {
"id": "category",
"type": "category"
}
}'
Parameters
Search query (minimum: 1 character)
Request body
Get parameter remapping
Get remapped values for a parameter.
POST /api/dataset/parameter/remapping
curl -X POST \
https://your-metabase.com/api/dataset/parameter/remapping \
-H 'Content-Type: application/json' \
-H 'X-Metabase-Session: SESSION_TOKEN' \
-d '{
"parameter": {
"id": "param1",
"type": "category"
},
"value": 123
}'
Request body
Value to get remapping for
Generate pivot table
Generate a pivoted dataset for a query.
curl -X POST \
https://your-metabase.com/api/dataset/pivot \
-H 'Content-Type: application/json' \
-H 'X-Metabase-Session: SESSION_TOKEN' \
-d '{
"database": 1,
"type": "query",
"query": {
"source-table": 5,
"aggregation": [["count"]],
"breakout": [["field", 12, null], ["field", 13, null]]
}
}'
Request body
Query with breakout fields for pivoting
Response
Returns pivoted data with row and column groupings.
Use pivot queries for creating cross-tab reports and matrices.