Search code examples
azure-data-explorerkql

Pass query to ADX UI thru URL params


Is it possible to generate links that contains the query we would like to pass to the Kusto Query UI?

Is there an API that could be used for that given reason?

Basically, the workflow I imagine is some link, containing the cluster name, database name, as well as the query string (encoded or something).

This would be for sharing purposes.

Thanks!


Solution

  • Found the answer!

    It seems like the Kusto.Explorer documentation provides a way to do it! I reverse engineered the copying feature from the UI, and realized that if you gzip compress then encode the query, you can pass it in the URL:

    https://dataexplorer.azure.com/clusters/<your_cluster_name>/databases/<your_database_name>?query=<your compressed+encoded query>

    In python, it would look like this:

    import base64
    import gzip
    query = "your Kusto query"
    encoded_bytes = gzip.compress(query.encode('utf-8'))
    encoded_query = base64.b64encode(encoded_bytes).decode('utf-8')
    print(encoded_query)