Hi!
I'm working with the Metabase API and run into some issues passing parameters to different endpoints.
This works properly using the api/:card-id/query/:export-format
endpoint:
params = [
{
"type":"category",
"target":[
"variable",
[
"template-tag",
"id"
]
],
"value":"1234"
},
{
"type":"date/single",
"target":[
"variable",
[
"template-tag",
"start_date"
]
],
"value":"2021-04-01"
}
]
encoded_params = str(urllib.parse.quote_plus(json.dumps(params)))
response = requests.post(f'https://metabase.mycompany.ai/api/card/cardId/query/json?parameters={encoded_params}',
headers=headers)
But I would rather use api/card/:card-id/query
without the export-format so I can access the response with response.json()['data']['rows']
(Basically the request above returns a list of dicts while the one I want to use returns a list of lists each one representing a row)
The thing is: I understand api/car/:card-id/query
receives parameters in the body of the request, but I don't seem to get it right. I've tried:
params = {"parameters": [
{
"type":"category",
"target":[
"variable",
[
"template-tag",
"id"
]
],
"value":"1234"
},
{
"type":"date/single",
"target":[
"variable",
[
"template-tag",
"start_date"
]
],
"value":"2021-04-01"
}
]}
json_params = json.dumps(params)
response = requests.post(https://metabase.mycompany.ai/api/card/cardId/query',
headers=headers,
json=json_params
)
And I've also tried passing the parameters as a dict in the data
argument of the requests.post
function.
Both ways I get a response but as if the parameters were completely ignored (basically it runs the query with its default parameters).
Please help, thanks in advance!
Edit: for clarity