image

I have a query on redash frontend with these parametric variables. I am using the Python api to fetch the data:

body = {“parameters”:{“start_date”:“2020-01-01”,“end_date”:“2020-01-10”}}
headers = {‘Authorization’: ‘Key mykey’}
response = requests.post(url =myurl,headers=headers,body = body)

I am getting error that no values for start_date or end_date have been specified.

Hi :wave:

This is probably a typo in a parameter name somewhere. Can you make a get request to api/queries/<query_id> and share with us the content of the parameters key in the response?

Also if you use date range parameters (instead of single date parameters) then you need to POST them in like so:

{
  "parameters": {
    "some_date": {
      "start": "2020-01-1",
      "end": "2020-01-31"
    }
  }
}

Hey Kasim,

Thanks for reaching out buddy. I tried every possible combination of parameters through postman and in the script but i couldnt get a direct post request to results api to work. I then realized that it would be better if try to understand the polling refresh script on redash toolbelt. Dove a little deeper into that and I was able to get the script running for my query on redash.

If you are part of the dev team at redash, I would strongly suggest to update documentation on API page, where it should explain that the logical flow for writing an api in python should be to first get the job value from ‘refresh’ end point and then use that value as input to ‘results’ end point to get your query results as json response. Also parameters go in as p_“your parameter name” and not in the format specified on the api page.

Once again, thanks for reaching out man, cheers :slight_smile:

On the contrary, the p_ parameter type API is being deprecated. The API page (badly) documents the “right” way to do it.

At the moment there are two endpoints: /refresh and /results.

  • The /refresh endpoint uses query string parameters preceded by p_. This one is going away.
  • The /results endpoint uses POSTed JSON with a parameters key and is the “right” way.

The API docs suck.

Glad you found a solution. Just hope it doesn’t break for you later.