GitHub user dosubot[bot] added a comment to the discussion: How to get permission id for datasource access on specific dataset using Superset 5.0.0 endpoint?
<!-- Answer --> To get the permission ID for datasource access on a specific dataset in Superset 5.0.0, you need to: 1. Fetch the dataset metadata using `/api/v1/dataset/{id}` to get the database name, table name, and dataset ID. 2. Construct the permission string in the format `[database_name].[table_name](id:dataset_id)` (for example, `[mydb].[mytable](id:123)`) [[source]](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/connectors/sqla/models.py). 3. Query `/api/v1/security/permissions-resources/` and filter for entries where `permission_name` is `datasource_access` and `view_menu_name` matches your constructed permission string. The returned object will have the permission ID you need [[source]](https://github.com/apache/superset/discussions/33878). 4. Assign this permission to a role by sending a payload with the permission ID to `/api/v1/security/roles/{role_id}/permissions` [[source]](https://github.com/apache/superset/discussions/33878). There is no single endpoint that maps dataset ID directly to permission ID; you must construct the permission string and search the permissions-resources endpoint. Here’s a Python snippet to illustrate steps 1–3: ```python import requests # Authenticate and get CSRF token (see Superset API docs for details) session = requests.Session() session.headers.update({"Authorization": f"Bearer {access_token}"}) session.headers.update({"X-CSRFToken": csrf_token}) # 1. Get dataset metadata dataset_id = 123 resp = session.get(f"http://localhost:8088/api/v1/dataset/{dataset_id}") data = resp.json()["result"] database_name = data["database"]["database_name"] table_name = data["table_name"] # 2. Construct permission string perm_string = f"[{database_name}].[{table_name}](id:{dataset_id})" # 3. Find permission ID resp = session.get("http://localhost:8088/api/v1/security/permissions-resources/") for perm in resp.json()["result"]: if perm["permission_name"] == "datasource_access" and perm["view_menu_name"] == perm_string: permission_id = perm["id"] break ``` You can then assign `permission_id` to a role using the roles API. Make sure you’re authenticated and include the CSRF token in your requests. <!-- 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/2ee43a01-bade-4010-84d9-250848c7a9b7?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/2ee43a01-bade-4010-84d9-250848c7a9b7?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/2ee43a01-bade-4010-84d9-250848c7a9b7?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/2ee43a01-bade-4010-84d9-250848c7a9b7?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2ee43a01-bade-4010-84d9-250848c7a9b7?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/2ee43a01-bade-4010-84d9-250848c7a9b7?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2ee43a01-bade-4010-84d9-250848c7a9b7?feedback_type=other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github)& nbsp;[](https://go.dosu.dev/discord-bot) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/34571) GitHub link: https://github.com/apache/superset/discussions/34571#discussioncomment-14013885 ---- This is an automatically sent email for notifications@superset.apache.org. To unsubscribe, please send an email to: notifications-unsubscr...@superset.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org