Get SQL queries by query slug or query id

  • 24 January 2019
  • 2 replies

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

2 replies

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

Thank you - that was a hard find. So simple - yet not self revealing itself, for someone searching through the api docs 🙂