Where to get API "query" schema specification?


I’m trying to use the POST /api/dataset/ endpoint which specifies a query parameter, however I haven’t been able to find documentation for what format query should be.

API documentation: https://github.com/metabase/metabase/blob/master/docs/api-documentation.md

I have found references to the format in other posts such as the following:

query: {"database":-1337,"type":"query","query":{"source_table":"card__3","filter":["AND",["CONTAINS",["field-id",["field-literal","email","type/Text"]],"example"]]},"parameters":[]}

Can someone point me to the definition for this?

Also, is there any way to send in a raw SQL statement via the API?



Hi @grokify
It sounds like you’re looking for the MBQL’98 schema


For an SQL question the JSON part of the request should look something like this:

 {database: 1,
  native: {query: "select count(*) from ORDERS"},
  type: "native"}

and if you want to use MBQL:

{database: 1,
 query: {source-table: 2, 
             breakout: [["binning-strategy", ["field-id", 14], "default"]]
             aggregation: [["avg", ["field-id", 17]]]},
 type: "query"}


Thanks sbelak. I have this working for POST /api/dataset now using the native query, however, two issues have come up:

  1. When I call POST /api/dataset with a native query, the response returns JSON but it does not include the Content-Type header which would ideally be application/json or application/json; charset=utf-8
  2. When I call POST /api/dataset/json in an attempt to get a JSON Content-Type response header, I get the following error: 400 Bad Request - {"errors":{"query":"value must be a valid JSON string."}}. It seems like there are request differences in POST /api/dataset and POST /api/dataset/json in addition to the return format type.

This lack of a Content-Type header is causing an issue with the Go SDK I’m auto-building which I’m looking to resolve.


Mind opening an issue for this. They should work the same (and we should probably also set all the appropriate headers).