Filtered Chart Data via API #34668
-
Hi, I'm a beginner to Apache Superset and I've been exploring the API. Specifically there's a use case I would like to employ but so far have not found a way to do it. Essentially I want to fetch chart data in a format like JSON, similar to the /api/v1/chart/data call, but be able to filter those results in the request itself. So if the chart has a column named ID, per example, I want to be able to apply a filter such as "ID == [value]" or "WHERE ID LIKE [value]". Is this at all possible? If so how? I have played around with Jinja Templating and Dashboard filters but haven't found a way to make them interact with the API call. I have also looked into Preset but that currently isn't an option so I was looking for alternatives that do not employ third party tools. In case it's relevant, I'm running Apache Superset on a Docker Compose container within an Ubuntu VM. Thank you in advance for any forthcoming replies. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi @satanic-panic! I'm Dosu and I’m helping the superset team. Yes, you can filter chart data directly via the Here's a minimal example for filtering by equality and LIKE: {
"datasource": "your_table_or_dataset_id__table",
"queries": [
{
"filters": [
{ "col": "ID", "op": "==", "val": 123 },
{ "col": "NAME", "op": "LIKE", "val": "%foo%" }
]
}
]
} Replace Jinja templating and dashboard filters do not interact directly with this API call. Jinja is only relevant if you use it in the For more details, see the relevant code and schema and discussion on API usage. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
-
Answering my own question because I found the solution. Dosu didn't solve my issue but pointed me in the right direction. For future reference of anyone trying to do this like me and not finding any resources online (like I didn't) the request is as follows: POST /api/v1/chart/data Example payload: |
Beta Was this translation helpful? Give feedback.
Answering my own question because I found the solution. Dosu didn't solve my issue but pointed me in the right direction. For future reference of anyone trying to do this like me and not finding any resources online (like I didn't) the request is as follows:
POST /api/v1/chart/data
Example payload:
{
"datasource": {
"id": 123,
"type": "table"
},
"queries": [
{
"columns": ["col1", "col2"],
"filters": [
{ "col": "col1", "op": "==", "val": 123 }
],
"metrics": [],
"row_limit": 1000
}
],
"result_format": "json",
"result_type": "full"
}