Python Metabase API with filter

Hello,
I need help to understand how to use the python API on a question with a filter. I have a question with a filter, a number, on which I want to have the result on python. I connect to my metabase account, and get the query result with : metabase.post("/card/300/query"). But when I want to apply the filter “Number”, I am a little lost. I tried to follow this, found on another post :
‘’’’’
Parameters should go at the URL , encoded in JSON, in the following format:
[{“type”:“number”, “target”:[“variable”,[“template-tag”,“Number”]],“value”:“400”}]
‘’’’’
With payload = {“type”:“number”, “target”:[“variable”,[“template-tag”,“Number”]],“value”:“400”}
& metabase.post("/card/300/query/json", json = payload)
Does anybody knows how to do it ?
Thanks,
CS.

Same issue here.

This is the payload source i'm getting from devtools in Chrome:
{"database":5,"query":{"source-table":1208,"aggregation":[["count"]],"breakout":[["field",27831,None]],"filter":["and",[">",["field",27829,None],"2022-02-03"],["=",["field",27831,None],628506]]},"type":"query","parameters":[]}

I've tried everything to parse that into a POST /api/card/:card-id/query, including the requests parameters "json=", "data=", "params=".
Also tried changing 'Content-Type': 'application/x-www-form-urlencoded' to 'application/json' on the headers request.

Pretty sure there's something about the payload format that must be adjusted before parsing it into a post request, but also, didn't find any clear solution in any topic. Seems like the "parameters" key must be filled with some filtering, but no clear explanation on that, even on github wrappers for Python.
I would also appreciate a hand for a new dev here :slight_smile:

In your devtools result, you have "parameters":[]. This means you are not passing any parameters.
Once you get the correct devtools results, you can use this function from this Python wrapper for Metabase API, to get what you need (pass the value of parameters from devtools to the above function).

Hey @King_Edward, thanks for answering.

Yep, I'm messing around with tables and cards, filtering data, but the parameters key seems to be allways empty:

I will keep trying

Fixed it. Looks like the endpoint I was using was incorrect, @King_Edward.
Even though I was manipulating a card or question on Metabase, the endpoint in the request headers was: 1. Request URL: https://metabase.asaas.com/api/dataset.

So I've just did: response = requests.post('https://metabase.asaas.com/api/dataset', headers=headers, data=json_params),

where the params was:
params = {"database":5,

      "query":{"source-table":1208,

               "aggregation":[["count"]],

               "breakout":[["field",27831,None]],

               "filter":["and",[">",["field",27829,None],"2022-02-03"],["=",["field",27831,None],1168223]]},

      "type":"query",

      "parameters":[]}

json_params = json.dumps(params)

@ClementS, pls check the headers of your requests in devtools, maybe the endpoint you should use is also the dataset one..
Thank you all