Get SQL queries by query slug or query id

done
api
normal_priority
sql
reply

(Girish G) #1

Have a requirement to extract SQL that gets executed given a query slug or query id.
I see Looker UI uses /api/internal/dataflux/queries/sql/ to get SQL and display on SQL tab. Is there a way this can be achieved through any APIs


(Paola) #3

Hey @Girish_G,

You can definitely extract the SQL generated using a query ID via Looker’s API. Using the run_query API endpoint, we can provide the query ID and set the result format to SQL. For example, the request URL would look like https://<yourdomain>.com:19999/api/3.0/queries/<queryid>/run/sql.

You could also try this out using the interactive API documentation available on your Looker instance. You can get to the interactive API documentation by navigating to the Admin/API page in Looker and clicking “View API Docs”. On that page, you should see the run_query endpoint where you can specify a query ID and result format as well.