GitHub user dosubot[bot] added a comment to the discussion: Is there any possibility to filter datasets via tags (or some parameter) using API ?
<!-- Greeting --> Hi @skiermax! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the superset team. <!-- Answer --> You can't filter datasets by tags directly via the /api/v1/dataset endpoint. The dataset API supports filtering by string parameters like table_name, description, schema, database name, owners, and uuid using the q query parameter (Rison or JSON) [example](https://github.com/apache/superset/blob/master/superset/datasets/api.py). If you want to filter datasets by tags (like you do for dashboards), you need to use the TagRestApi's /api/v1/tag/get_objects/ endpoint. Pass the tag name or ID and set types=4 (where 4 is the object_type for datasets, as defined in tags/models.py). This will return all datasets associated with the specified tag [see details](https://github.com/apache/superset/blob/master/superset/tags/api.py). Example: To get datasets tagged with "mytag": ``` GET /api/v1/tag/get_objects/?tags=mytag&types=4 ``` To filter datasets by string (e.g., table name contains "sales"): ``` GET /api/v1/dataset/?q={"filters":[{"col":"table_name","opr":"ct","value":"sales"}]} ``` So, use the tagging API to get datasets by tag, and the dataset API for string-based filtering. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/3032ecb2-fb5c-428e-ac4e-5cff80fcb3c8?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/3032ecb2-fb5c-428e-ac4e-5cff80fcb3c8?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/3032ecb2-fb5c-428e-ac4e-5cff80fcb3c8?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/3032ecb2-fb5c-428e-ac4e-5cff80fcb3c8?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3032ecb2-fb5c-428e-ac4e-5cff80fcb3c8?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/3032ecb2-fb5c-428e-ac4e-5cff80fcb3c8?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/3032ecb2-fb5c-428e-ac4e-5cff80fcb3c8?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github) [](https://cursor.com/link/prompt?text=You%20can%27t%20filter%20datasets%20by%20tags%20directly%20via%20the%20/api/v1/dataset%20endpoint.%20The%20dataset%20API%20supports%20filtering%20by%20string%20parameters%20like%20table_name%2C%20description%2C%20schema%2C%20database%20name%2C%20owners%2C%20and%20uuid%20using%20the%20q%20query%20parameter%20%28Rison%20or%20JSON%29%C2%A0%5Bexample%5D%28https%3A//github.com/apache/superset/blob/master/superset/datasets/api.py%29.%0A%0AIf%20you%20want%20to%20filter%20datasets%20by%20tags%20%28like%20you%20do%20for%20dashboards%29%2C%20you%20need%20to%20use%20the%20TagRestApi%27s%20/api/v1/tag/get_objects/%20endpoint.%20Pass%20the%20tag%20name%20or%20ID%20and%20set%20types%3D4%20%28where%204%20is%20the%20object_type%20for%20datasets%2C%20as%20defined%20in %20tags/models.py%29.%20This%20will%20return%20all%20datasets%20associated%20with%20the%20specified%20tag%C2%A0%5Bsee%20details%5D%28https%3A//github.com/apache/superset/blob/master/superset/tags/api.py%29.%0A%0AExample%3A%20%20%0ATo%20get%20datasets%20tagged%20with%20%22mytag%22%3A%0A%60%60%60%0AGET%20/api/v1/tag/get_objects/%3Ftags%3Dmytag%26types%3D4%0A%60%60%60%0A%0ATo%20filter%20datasets%20by%20string%20%28e.g.%2C%20table%20name%20contains%20%22sales%22%29%3A%0A%60%60%60%0AGET%20/api/v1/dataset/%3Fq%3D%7B%22filters%22%3A%5B%7B%22col%22%3A%22table_name%22%2C%22opr%22%3A%22ct%22%2C%22value%22%3A%22sales%22%7D%5D%7D%0A%60%60%60%0A%0ASo%2C%20use%20the%20tagging%20API%20to%20get%20datasets%20by%20tag%2C%20and%20the%20dataset%20API%20for%20string-based%20filtering.) [](https://go.dosu.dev/discord-bot) [](https://twitter.com/in tent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/37137) GitHub link: https://github.com/apache/superset/discussions/37137#discussioncomment-15498865 ---- This is an automatically sent email for [email protected]. To unsubscribe, please send an email to: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
