Execute a query

POST /api/dataset

Execute a query and retrieve the results in the usual format.

Body Required

  • database integer(int64)
  • type string

    Values are native or query.

  • native object
    Hide native attribute Show native attribute object
    • query string
  • query object

    Dataset query request and response object

    Hide query attributes Show query attributes object
    • source_table integer(int64)
    • limit integer(int64)
    • page object
      Hide page attributes Show page attributes object
      • page integer(int64)
      • items integer(int64)
  • constraints object
    Hide constraints attributes Show constraints attributes object
    • max-results integer(int64)
    • max-results-bare-rows integer(int64)

Responses

  • 200

    successful operation

    Hide response attributes Show response attributes object
    • started_at string(date-time)
    • json_query object
      Hide json_query attributes Show json_query attributes object
      • type string

        Values are native or query.

      • database integer(int64)
      • native object
        Hide native attribute Show native attribute object
        • query string
      • query object

        Dataset query request and response object

        Hide query attributes Show query attributes object
        • source_table integer(int64)
        • limit integer(int64)
        • page object
          Hide page attributes Show page attributes object
          • page integer(int64)
          • items integer(int64)
      • constraints object
        Hide constraints attributes Show constraints attributes object
        • max-results integer(int64)
        • max-results-bare-rows integer(int64)
    • average_execution_time string

      type unknown

    • status string
    • context string
    • row_count integer(int64)
    • running_time integer(int64)
    • data object
      Hide data attributes Show data attributes object
      • columns array[string]
      • native_form object
        Hide native_form attributes Show native_form attributes object
        • query string
        • params string

          unknown type

      • cols array[object]
        Hide cols attributes Show cols attributes array[object]
        • description string
        • table_id integer(int64)
        • schema_name string
        • special_type string
        • name string
        • source string
        • remapped_from string

          unknown type

        • extra_info object

          can be '{"target_table_id":517}'

        • fk_field_id string

          unknown type

        • remapped_to string

          unknown type

        • id integer(int64)
        • visibility_type string
        • target object
          Hide target attributes Show target attributes object
          • id integer(int64)
          • name string
          • display_name string
          • table_id integer(int64)
          • description string
          • base_type string
          • special_type string
          • visibility_type string
        • display_name string
        • fingerprint object
          Hide fingerprint attributes Show fingerprint attributes object
          • global object
            Hide global attribute Show global attribute object
            • distinct-count integer(int64)
          • type object

            map[string]DatasetQueryResultsColFingerprintType results in map[string]interface{}

        • base_type string
      • results_metadata object
        Hide results_metadata attributes Show results_metadata attributes object
        • checksum string
        • columns array[object]
          Hide columns attributes Show columns attributes array[object]
          • base_type string
          • display_name string
          • name string
          • special_type string
      • rows_truncated integer(int64)
POST /api/dataset
curl \
 -X POST http://metabase.example.com/api/dataset \
 -H "Content-Type: application/json" \
 -d '{"database":0,"native":{"query":"query"},"query":{"limit":1,"page":{"page":5,"items":5},"source_table":6},"type":"native","constraints":{"max-results":2,"max-results-bare-rows":7}}'
Request example
{
  "database": 0,
  "native": {
    "query": "query"
  },
  "query": {
    "limit": 1,
    "page": {
      "page": 5,
      "items": 5
    },
    "source_table": 6
  },
  "type": "native",
  "constraints": {
    "max-results": 2,
    "max-results-bare-rows": 7
  }
}
Request examples
{
  "type": "native",
  "query": {
    "page": {
      "page": 5,
      "items": 5
    },
    "limit": 1,
    "source_table": 6
  },
  "native": {
    "query": "query"
  },
  "database": 0,
  "constraints": {
    "max-results": 2,
    "max-results-bare-rows": 7
  }
}
Response examples (200)
{
  "json_query": {
    "database": 0,
    "native": {
      "query": "query"
    },
    "query": {
      "limit": 1,
      "page": {
        "page": 5,
        "items": 5
      },
      "source_table": 6
    },
    "type": "native",
    "constraints": {
      "max-results": 2,
      "max-results-bare-rows": 7
    }
  },
  "data": {
    "results_metadata": {
      "columns": [
        {
          "special_type": "special_type",
          "base_type": "base_type",
          "name": "name",
          "display_name": "display_name"
        },
        {
          "special_type": "special_type",
          "base_type": "base_type",
          "name": "name",
          "display_name": "display_name"
        }
      ],
      "checksum": "checksum"
    },
    "rows_truncated": 1,
    "native_form": {
      "query": "query",
      "params": "params"
    },
    "columns": [
      "columns",
      "columns"
    ],
    "rows": [
      [
        "{}",
        "{}"
      ],
      [
        "{}",
        "{}"
      ]
    ],
    "cols": [
      {
        "special_type": "special_type",
        "description": "description",
        "remapped_to": "remapped_to",
        "schema_name": "schema_name",
        "source": "source",
        "table_id": 2,
        "display_name": "display_name",
        "fk_field_id": "fk_field_id",
        "target": {
          "special_type": "special_type",
          "base_type": "base_type",
          "name": "name",
          "description": "description",
          "id": 7,
          "display_name": "display_name",
          "table_id": 1,
          "visibility_type": "visibility_type"
        },
        "extra_info": "{}",
        "base_type": "base_type",
        "name": "name",
        "fingerprint": {
          "global": {
            "distinct-count": 1
          },
          "type": "{}"
        },
        "id": 4,
        "remapped_from": "remapped_from",
        "visibility_type": "visibility_type"
      },
      {
        "special_type": "special_type",
        "description": "description",
        "remapped_to": "remapped_to",
        "schema_name": "schema_name",
        "source": "source",
        "table_id": 2,
        "display_name": "display_name",
        "fk_field_id": "fk_field_id",
        "target": {
          "special_type": "special_type",
          "base_type": "base_type",
          "name": "name",
          "description": "description",
          "id": 7,
          "display_name": "display_name",
          "table_id": 1,
          "visibility_type": "visibility_type"
        },
        "extra_info": "{}",
        "base_type": "base_type",
        "name": "name",
        "fingerprint": {
          "global": {
            "distinct-count": 1
          },
          "type": "{}"
        },
        "id": 4,
        "remapped_from": "remapped_from",
        "visibility_type": "visibility_type"
      }
    ]
  },
  "context": "context",
  "started_at": "2000-01-23 04:56:07 +0000",
  "running_time": 3,
  "average_execution_time": "average_execution_time",
  "status": "status",
  "row_count": 9
}
Response examples (200)
{
  "data": {
    "cols": [
      {
        "id": 4,
        "name": "name",
        "source": "source",
        "target": {
          "id": 7,
          "name": "name",
          "table_id": 1,
          "base_type": "base_type",
          "description": "description",
          "display_name": "display_name",
          "special_type": "special_type",
          "visibility_type": "visibility_type"
        },
        "table_id": 2,
        "base_type": "base_type",
        "extra_info": "{}",
        "description": "description",
        "fingerprint": {
          "type": "{}",
          "global": {
            "distinct-count": 1
          }
        },
        "fk_field_id": "fk_field_id",
        "remapped_to": "remapped_to",
        "schema_name": "schema_name",
        "display_name": "display_name",
        "special_type": "special_type",
        "remapped_from": "remapped_from",
        "visibility_type": "visibility_type"
      },
      {
        "id": 4,
        "name": "name",
        "source": "source",
        "target": {
          "id": 7,
          "name": "name",
          "table_id": 1,
          "base_type": "base_type",
          "description": "description",
          "display_name": "display_name",
          "special_type": "special_type",
          "visibility_type": "visibility_type"
        },
        "table_id": 2,
        "base_type": "base_type",
        "extra_info": "{}",
        "description": "description",
        "fingerprint": {
          "type": "{}",
          "global": {
            "distinct-count": 1
          }
        },
        "fk_field_id": "fk_field_id",
        "remapped_to": "remapped_to",
        "schema_name": "schema_name",
        "display_name": "display_name",
        "special_type": "special_type",
        "remapped_from": "remapped_from",
        "visibility_type": "visibility_type"
      }
    ],
    "rows": [
      [
        "{}",
        "{}"
      ],
      [
        "{}",
        "{}"
      ]
    ],
    "columns": [
      "columns",
      "columns"
    ],
    "native_form": {
      "query": "query",
      "params": "params"
    },
    "rows_truncated": 1,
    "results_metadata": {
      "columns": [
        {
          "name": "name",
          "base_type": "base_type",
          "display_name": "display_name",
          "special_type": "special_type"
        },
        {
          "name": "name",
          "base_type": "base_type",
          "display_name": "display_name",
          "special_type": "special_type"
        }
      ],
      "checksum": "checksum"
    }
  },
  "status": "status",
  "context": "context",
  "row_count": 9,
  "json_query": {
    "type": "native",
    "query": {
      "page": {
        "page": 5,
        "items": 5
      },
      "limit": 1,
      "source_table": 6
    },
    "native": {
      "query": "query"
    },
    "database": 0,
    "constraints": {
      "max-results": 2,
      "max-results-bare-rows": 7
    }
  },
  "started_at": "2000-01-23T04:56:07+00:00",
  "running_time": 3,
  "average_execution_time": "average_execution_time"
}