---
title: "Get the SQL query for a report element"
method: GET
path: "/v2/reports/{reportId}/elements/{elementId}/query"
tags: ["Reports"]
---

# Get the SQL query for a report element

`GET /v2/reports/{reportId}/elements/{elementId}/query`

## Request

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

This endpoint retrieves the SQL query associated with a specific element in a report. It allows users to view and understand how the data for that element is being processed and transformed.

### Usage notes
- Retrieve the **reportId** by calling the [/v2/reports](https://help.sigmacomputing.com/reference/list-reports) endpoint.
- Retrieve the **elementId** by first calling the [/v2/reports/{reportId}/pages](listreportpages) endpoint, then calling the [/v2/reports/{reportId}/pages/{pageId}/elements](listreportpageelements) endpoint.

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

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

- `reportId` string, required
- `elementId` string, required

## Response `200`

The response body.

- ReportsGetReportElementQueryResponse200
  - `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)
