Metabase API POST /api/card/query WITH FILTERS


I'd like to get the results from a Metabase question (that has a required filter) using the API. This is a test question with only 1 filter (a simple limit on the number of results).
I use the api post api/card/query from the official documentation and adapted it for Node.js.

I've found thanks to the Google Chrome DevTools that the parameters in the query are {"type":"category","value":"3","target":["variable",["template-tag","limit"]]}]}.

So, here is my code:
let param = '[{"ignore_cache":false,"parameters":[{"type":"category","value":"3","target":["variable",["template-tag","limit"]]}]}]'; // need to add '[' + ']' and convert in string

let encoded = encodeURI(param); // encode the parameter

response = await"" + "QUESTION_ID" + "/query/json?parameters=" + encoded,

But I get error_type: 'invalid-query' + Input to substitute-native-parameters__8 does not match schema. I don't know what I'm doing wrong here.

Do you have an idea where the problem is coming from ?

Thanks in advance,



Hi @Louis
Your topic title says you're using one endpoint, but your code example says you're using a different.

POST /api/card/:card-id/query is not the same endpoint as POST /api/card/:card-id/query/:export-format

Have a look here: API POST /api/card/:card-id/query/:export-format with parameters

Hi @flamber,

Indeed I mixed things up. The "ignore_cache" is not useful when using POST /api/card/:card-id/query/:export-format.

Thanks a lot for your help !