---
title: "Get the SQL query for a workbook element"
method: GET
path: "/v2/workbooks/{workbookId}/elements/{elementId}/query"
tags: ["Workbooks"]
---

# Get the SQL query for a workbook element

`GET /v2/workbooks/{workbookId}/elements/{elementId}/query`

## Request

- Base URL: `https://api.sigmacomputing.com`
- URL: `https://api.sigmacomputing.com/v2/workbooks/{workbookId}/elements/{elementId}/query`
- Auth: HTTP bearer

This endpoint retrieves the SQL query associated with a specific element in a workbook. It allows users to view and understand how the data for that element is being processed and transformed, which is critical for debugging, optimization, and educational purposes.

### Usage notes
- Retrieve the **workbookId** by calling the [/v2/workbooks](https://help.sigmacomputing.com/reference/list-workbooks) endpoint.
- Retrieve the **elementId** for a custom SQL element by calling the [/v2/workbooks/{workbookId}/queries](https://help.sigmacomputing.com/reference/list-workbook-queries) endpoint.
- To retrieve the query for an element from a version-tagged workbook, pass the `tagName` in the query parameters with the tag name. Retrieve the tag name by calling the [/v2/workbooks](https://help.sigmacomputing.com/reference/list-workbooks) endpoint and using the `tags.name` included in the response for a given workbook.
- To retrieve the query for an element from a saved view (formerly called a bookmark), pass the `bookmarkId` in the query parameters. Retrieve the bookmarkId by calling the [/v2/workbooks/{workbookId}/bookmarks](https://help.sigmacomputing.com/reference/get-workbook-bookmarks) or [/v2/workbooks/{workbookId}/tags/:tagName/bookmarks](https://help.sigmacomputing.com/reference/get-tagged-workbook-bookmarks) endpoints.

### Usage scenarios
- **Development and debugging:** Provides developers and analysts with the ability to retrieve and review the SQL code behind workbook 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 workbooks.

### Best practices
- Ensure proper access controls are in place to manage who can view potentially sensitive query information.
- 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.

## Path parameters

- `workbookId` string, required
- `elementId` string, required

## Query parameters

- `page` string
- `limit` number, double
- `tagName` string
- `bookmarkId` string

## Response `200`

The response body.

- WorkbooksGetElementQueryResponse200
  - `elementId` string, required
  - `name` string
  - `sql` string
  - `error` string

---

[API](https://skmtc.dev/sigmacomputing/apis/sigma-rest-api.md) - [All operations](https://skmtc.dev/sigmacomputing/apis/sigma-rest-api/llms.txt) - [OpenAPI document](https://skmtc.dev/sigmacomputing/apis/sigma-rest-api/revisions/fb6036208c49?raw)
