Hacking with Redash

Under what circumstances will the id of the table query_result be updated to the latest_query_data_id field of the query?

I want to get the id value of query_result directly by the id of the queries?
I found a field in the queries table: latest_query_data_id

But when will this value be updated?

Redash updates a query’s latest_query_data_id whenever it executes successfully.

The query_results and queries tables are not directly linked, however. Results are looked up based on the query_hash which will depend on the specific parameters used in a given execution.

If you are querying the metadata db directly, you can actually join these two tables using the query_hash fields. But the JOIN is null for any query that uses parameters.

I wrote that;

  @classmethod
  def get_id_by_query_hash(cls, queries_id):
       query_id = (
           db.session.query(distinct(cls.id))
            .join(
                Query, Query.query_hash == cls.query_hash
            )
            .filter(Query.id.in_(queries_id))
        )
        return query_id

I think it can be through the interface:/api/queries/{queryId}/jobs/{query_hash}
When the returned status is equal to 3, I can get the query_result_id

The previous problems have been solved, and I now have another problem, that is, how to skip login verification when downloading excel and csv files;
this interface:/api/queries/<query_id>/results.<filetype>

The use of apikey you mentioned earlier does not seem to work here,
download api does not use ajax, it is impossible to add apikey in the header!

Do you have any good solutions?

@susodapop
hello,I found it was intercepted here,

@login_manager.unauthorized_handler
def redirect_to_login():
    if request.is_xhr or "/api/" in request.path:
        response = jsonify(
            {"message": "Couldn't find resource. Please login and try again."}
        )
        response.status_code = 404
        return response

    login_url = get_login_url(next=request.url, external=False)

    return redirect(login_url)

Is there any way to skip the download api separately?

This is actually covered in our documentation:

/api/query_results/<query_result_id>

  • GET: Returns a query result
    • Appending a filetype of .csv or .json to this request will return a downloadable file. If you append your api_key in the query string, this link will work for non-logged-in users.