Hey,
I need to use Metabase API /card/{card_id}/query/json to retrieve json data from a Question with a multi-dropdown string type of filter applied. What should I put in the Body section in the API call? Below is what I gathered from the Chrome Network panel.
curl "http://xxx.xxx.xx.xxx:3000/api/card/310/query" ^
-H "Accept: application/json" ^
-H "Accept-Language: zh-CN,zh;q=0.9,zh-TW;q=0.8" ^
-H "Content-Type: application/json" ^
-H "Cookie: metabase.DEVICE=bf3403da-e254-4f85-b332-e293c0e39775; metabase.TIMEOUT=alive; metabase.SEEN_ALERT_SPLASH=true; metabase.SESSION=xxxxxxxxxx ^
-H "Origin: http://xxx.xxx.xx.xxx:3000" ^
-H "Proxy-Connection: keep-alive" ^
-H "Referer: http://xxx.xxx.xx.xxx:3000/question/310?^%^3Fbrand=^%^E4^%^B8^%^80^%^E5^%^B8^%^86" ^
-H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36" ^
--data-raw "^{^\^"ignore_cache^\^":true,^\^"collection_preview^\^":false,^\^"parameters^\^":^[^{^\^"type^\^":^\^"string/=^\^",^\^"value^\^":^[^\^"^一^帆^\^"^],^\^"target^\^":^[^\^"dimension^\^",^[^\^"template-tag^\^",^\^"brand^\^"^]^],^\^"id^\^":^\^"0ef7a071-601e-718f-5e17-6faab45a6169^\^"^}^]^}" ^
--compressed ^
--insecure
I converted the above code to below json code per ChatGPT but the result returned from the API was still incorrect appears that the filter was not applied at all.
{
"ignore_cache": true,
"collection_preview": false,
"parameters": [
{
"type": "string/=",
"target": [
"dimension",
[
"template-tag",
"brand"
]
],
"value": [
"一帆"
],
"id": "0ef7a071-601e-718f-5e17-6faab45a6169"
}
]
}
Luiggi
April 14, 2023, 2:50pm
#3
try checking the
--data-raw "^{^\^"ignore_cache^\^":true,^\^"collection_preview^\^":false,^\^"parameters^\^":^[^{^\^"type^\^":^\^"string/=^\^",^\^"value^\^":^[^\^"^一^帆^\^"^],^\^"target^\^":^[^\^"dimension^\^",^[^\^"template-tag^\^",^\^"brand^\^"^]^],^\^"id^\^":^\^"0ef7a071-601e-718f-5e17-6faab45a6169^\^"^}^]^}" ^
section
that's where you send to the endpoint the filters
Yes, below is what I send in the Body section but the filter is failed to apply per the result returned. Can you please help check below script?
{
"ignore_cache": true,
"collection_preview": false,
"parameters": [
{
"type": "string/=",
"target": [
"dimension",
[
"template-tag",
"brand"
]
],
"value": [
"一帆"
],
"id": "0ef7a071-601e-718f-5e17-6faab45a6169"
}
]
}
TonyC
April 17, 2023, 9:17am
#5
Check the payload section instead of the header since it should be more clear what needs to be sent and make sure the payload matches the above