Good evening,

I’ve been trying to refresh a query using the api and I’m encountering some issues with it.
I’m using the code example provided here by arik: https://gist.github.com/arikfr/e3e434d8cfd7f331d499ccf351abbff9

If I use a normal text parameter it works like a charm
http://some.redash.url/api/queries/query_id/refresh?p_hello=world

But if I try the new date range parameters it returns nothing
http://some.redash.url/api/queries/query_id/refresh?p_Rango.start=2018-12-01&p_Rango.end=2019-01-01

Is there a way to make it work?

Cheers,
Fran

What version of Redash are you using?

Redash 6.0.0+b8536 (4780bd9c)

This was fixed in master and will be part of the next release.

1 Like

Awesome, thanks for the help arik :slight_smile:

How will the call be with the range parameter then? Like this?
http://some.redash.url/api/queries/query_id/refresh?p_Rango.start=2018-12-01&p_Rango.end=2019-01-01

Fran,

The /api/queries/:query_id/refresh endpoint will soon be deprecated. A newer API is available, which offers better security and could be shared easily. You can use this API by submitting a POST to /api/queries/:query_id/results. Query parameters should be passed as “parameters” in the request body.

So in your case, it would be:

POST http://some.redash.url/api/queries/123/results
Body:

  "Rango": {
    "start": "2018-12-01",
    "end": "2019-01-01"
  }
}

Please keep in mind that this API is currently available on master only, and will be part of the next release (7.0.0).

Let me know if there’s anything else I can help with,
rauchy

3 Likes

Thanks rauchy! is there any documentation for this new API?
If the /refresh endpoint won’t be a thing anymore, will there be a way to query for fresh results instead of the cached ones?

Best


Hi,My redash version is 7.0.0+b18042(4a978bad). But the new api is unuseful.

Hey @wonderful60, try changing "login_time" in your request body to "p_login_time". Then nest it in a larger object called parameters.

{
"parameters": {
   "p_login_time": { ... }
}

This line in the Redash source suggests that your parameter name should have p_ prepended. You can see the same thing in the gist linked above on line 40.

1 Like

Thanks @jesse ,it’s work.

1 Like

Then to refresh a query result, can I submit a POST request using my parameters and I will have updated results?

Thank you

It’s a two-step process:

  1. POST to the query endpoint with your new parameter values.
  2. GET the latest results using the ID returned from the first request.
1 Like

Hello all,

I’m using the new API to refresh the query with parameter. POST to /api/queries/:query_id/results. In the body of the request I added this structure

{
“Rango”: {
“start”: “2018-12-01”,
“end”: “2019-01-01”
}
}

Now, my question is which start and end should I write if I would like to refresh the query with a predefined range like d_last_30_days or d_last_60_days? Any suggestion?

The dynamic date ranges don’t work with the API because they are calculated by the javascript front-end. The redash-toolbelt library includes date_ranges.py which has equivalent calculations you can use:

here’s a simple example repl.it so you can see it in action [LINK]

1 Like