GitHub user dosubot[bot] added a comment to the discussion: Chart migration 
from one instance to another instance.

<!-- Answer -->
To fetch a dataset UUID by passing the database name in Superset (useful for 
checking dataset availability during chart migration), you can use the Superset 
REST API and its filtering capabilities.

Superset's DatasetRestApi supports listing datasets with filters, and the 
dataset listing includes both the UUID and the database name as fields. You can 
make a GET request to the `/api/v1/dataset/` endpoint with query parameters to 
filter by `database.database_name` and `table_name` (the dataset name). The 
response will include the dataset's UUID if it exists.

Example API call:
```
GET 
/api/v1/dataset/?q={"filters":[{"col":"database.database_name","opr":"eq","value":"YOUR_DATABASE_NAME"},{"col":"table_name","opr":"eq","value":"YOUR_TABLE_NAME"}]}
```
The response will contain the dataset details, including the `uuid` field if 
the dataset is present.

Alternatively, you can use the `/api/v1/dataset/get_or_create/` endpoint with a 
POST request, providing the `database_id` and `table_name` in the JSON body. 
This will return the dataset's ID (and create it if it doesn't exist), which 
you can then use to fetch the full dataset info (including UUID) via 
`/api/v1/dataset/{id}`. See the relevant implementation 
[here](https://github.com/apache/superset/blob/fc13a0fde5b775f6734a0280742f44ddc2acdadb/superset/datasets/api.py).

If you need to programmatically resolve the `database_id` from the database 
name, you can query the `/api/v1/database/` endpoint with a similar filter.

These approaches allow you to check dataset availability and fetch UUIDs in the 
target instance before migrating charts. The API is designed to support 
flexible filtering by related fields like database name and table name, making 
this workflow possible without direct database access or manual lookups. For 
more on the API's filtering and response structure, see the [DatasetRestApi 
code](https://github.com/apache/superset/blob/fc13a0fde5b775f6734a0280742f44ddc2acdadb/superset/datasets/api.py)
 and 
[BaseSupersetModelRestApi](https://github.com/apache/superset/blob/fc13a0fde5b775f6734a0280742f44ddc2acdadb/superset/views/base_api.py).


<!-- Dosu Comment Footer -->
*To reply, just mention my name [@dosu](https://go.dosu.dev/dosubot).*

---
<sup>How did I do? 
[Good](https://app.dosu.dev/response-feedback/9dbbd06c-07f4-4a43-ba9e-cb11b4ff6cc4?feedback_type=great_response)
 | 
[Irrelevant](https://app.dosu.dev/response-feedback/9dbbd06c-07f4-4a43-ba9e-cb11b4ff6cc4?feedback_type=irrelevant_answer)
 | 
[Incorrect](https://app.dosu.dev/response-feedback/9dbbd06c-07f4-4a43-ba9e-cb11b4ff6cc4?feedback_type=incorrect_sources)
 | 
[Verbose](https://app.dosu.dev/response-feedback/9dbbd06c-07f4-4a43-ba9e-cb11b4ff6cc4?feedback_type=too_verbose)
 | 
[Hallucination](https://app.dosu.dev/response-feedback/9dbbd06c-07f4-4a43-ba9e-cb11b4ff6cc4?feedback_type=hallucination)
 | [Report 
🐛](https://app.dosu.dev/response-feedback/9dbbd06c-07f4-4a43-ba9e-cb11b4ff6cc4?feedback_type=bug_report)
 | 
[Other](https://app.dosu.dev/response-feedback/9dbbd06c-07f4-4a43-ba9e-cb11b4ff6cc4?feedback_type=other)</sup>&nbsp;&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Sh
 are on 
X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/discussions/33668)

GitHub link: 
https://github.com/apache/superset/discussions/33668#discussioncomment-13350654

----
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

Reply via email to