Get the SQL query for a data model element

View as Markdown
This endpoint retrieves the underlying SQL query associated with a specific element in a data model. It allows users to view and understand how the data for that element is being processed and transformed, which is useful for debugging, optimization, and educational purposes. ### Usage notes - Retrieve the **dataModelId** by calling the [/v2/dataModels](https://help.sigmacomputing.com/reference/list-data-models) endpoint. - Retrieve the **elementId** by calling the [/v2/dataModels/{dataModelId}/elements](https://help.sigmacomputing.com/reference/list-data-model-elements) endpoint. - To retrieve the query for an element from a version-tagged data model, pass the `tagName` in the query parameters with the tag name. Retrieve the tag name by calling the [/v2/dataModels/{dataModelId}/tags](https://help.sigmacomputing.com/reference/list-data-model-tags) endpoint and using the `tagName` included in the response for a given data model. ### Usage scenarios - **Development and debugging:** Provides developers and analysts with the ability to retrieve and review the SQL code behind data model elements, facilitating troubleshooting and enhancements. - **Educational insight:** Useful for training purposes or for users learning to understand the impact of various transformations and filters applied within their Sigma data models. ### Best practices - Restrict who can retrieve query SQL with [folder and document permissions](https://help.sigmacomputing.com/docs/folder-and-document-permissions). [Column-level security (CLS)](https://help.sigmacomputing.com/docs/column-level-security) still applies to the data returned by those queries. - Use this endpoint as part of a regular review process to ensure that all queries are optimized and up to date with current data schemas.

Authentication

AuthorizationBearer

OAuth authentication of the form <token>.

Path parameters

dataModelIdstringRequired
elementIdstringRequired

Query parameters

tagNamestringOptional

Response

The response body.
elementIdstring
namestringOptional
sqlstringOptional
errorstringOptional