Option 1: Update your parameters to include a p_prefix. So last_name will become p_last_name.
When we tried this, we received a successful 200 response back from the refresh
endpoint, but the response content is HTML, so we’re not able to get the job id via response.json()['job']
. Adding 'Content-Type': 'application/json'
to the headers did not help.
Here’s the response:
{'_content': b'<!DOCTYPE html>\n<html ng-app="app" ng-strict-di>\n <head lang="en">\n <meta name="viewport" content="width=device-width, initial-scale=1.0">\n <meta charset="UTF-8">\n <base href="/">\n <title>Redash</title>\n <script src="/static/unsupportedRedirect.js" async></script>\n\n <link rel="icon" type="image/png" sizes="32x32" href="/static/images/favicon-32x32.png">\n <link rel="icon" type="image/png" sizes="96x96" href="/static/images/favicon-96x96.png">\n <link rel="icon" type="image/png" sizes="16x16" href="/static/images/favicon-16x16.png">\n <link href="/static/vendors~app.22941359f2e6f98e80a1.css" rel="stylesheet"><link href="/static/app.88ac1b6c8e87b2093dc8.css" rel="stylesheet"></head>\n\n <body ng-class="bodyClass">\n <section>\n <app-view></app-view>\n <div class="loading-indicator">\n <div id="css-logo">\n <div id="circle">\n <div></div>\n </div>\n <div id="point">\n <div></div>\n </div>\n <div id="bars">\n <div class="bar"></div>\n <div class="bar"></div>\n <div class="bar"></div>\n <div class="bar"></div>\n </div>\n </div>\n <div id="shadow"></div>\n </div>\n </section>\n <script type="text/javascript" src="/static/vendors~app.22941359f2e6f98e80a1.js"></script><script type="text/javascript" src="/static/app.88ac1b6c8e87b2093dc8.js"></script></body>\n</html>\n',
'_content_consumed': True,
'_next': None,
'status_code': 200,
'headers': {'Server': 'nginx', 'Date': 'Sat, 16 May 2020 00:52:38 GMT', 'Content-Type': 'text/html; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Vary': 'Accept-Encoding', 'Last-Modified': 'Sun, 27 Oct 2019 14:30:14 GMT', 'Cache-Control': 'public, max-age=0', 'Expires': 'Sat, 16 May 2020 00:52:38 GMT', 'ETag': 'W/"1572186614.0-1441-2955612552"', 'X-Frame-Options': 'deny', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'X-Download-Options': 'noopen', 'Content-Security-Policy': "; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'; default-src 'self'; frame-src redash.io; img-src 'self' http: https: data:; object-src 'none'; font-src 'self' data:", 'X-Content-Security-Policy': "; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'; default-src 'self'; frame-src redash.io; img-src 'self' http: https: data:; object-src 'none'; font-src 'self' data:", 'Referrer-Policy': 'strict-origin-when-cross-origin', 'Strict-Transport-Security': 'max-age=31536000', 'Content-Encoding': 'gzip'},
'raw': <urllib3.response.HTTPResponse at 0x119cd58d0>,
'url': 'https://redash.brilliant.org/api/queries/8086/refresh?p_first_name=UserFirstName&p_last_name=UserLastName&p_email=UserEmail',
'encoding': 'utf-8',
'history': [],
'reason': 'OK',
'cookies': <RequestsCookieJar[]>,
'elapsed': datetime.timedelta(microseconds=61661),
'request': <PreparedRequest [GET]>,
'connection': <requests.adapters.HTTPAdapter at 0x119b55e90>}
Option 2: Use the /results
endpoint instead and include your parameters in the JSON POST body as demonstrated in our doc pages.
When we tried this, we received the Missing parameter value for: first_name, last_name, email
error again.
Code:
s = requests.Session()
s.headers.update({
'Authorization': 'Key {}'.format(api_key),
'content-type': 'application/json'}
)
params = {
'first_name': 'User first name',
'last_name': 'User last name',
'email': 'useremail@mail.com',
}
data = {'parameters': params}
response = s.post('{}/api/queries/{}/result'.format(redash_url, query_id), data=data)
Response:
{'_content': b'{"job": {"status": 4, "error": "Missing parameter value for: first_name, last_name, email"}}',
'_content_consumed': True,
'_next': None,
'status_code': 400,
'headers': {'Server': 'nginx', 'Date': 'Sat, 16 May 2020 00:40:36 GMT', 'Content-Type': 'application/json', 'Content-Length': '92', 'Connection': 'keep-alive', 'X-Frame-Options': 'deny', 'X-XSS-Protection': '1; mode=block', 'X-Content-Type-Options': 'nosniff', 'X-Download-Options': 'noopen', 'Content-Security-Policy': "; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'; default-src 'self'; frame-src redash.io; img-src 'self' http: https: data:; object-src 'none'; font-src 'self' data:", 'X-Content-Security-Policy': "; script-src 'self' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; frame-ancestors 'none'; default-src 'self'; frame-src redash.io; img-src 'self' http: https: data:; object-src 'none'; font-src 'self' data:", 'Referrer-Policy': 'strict-origin-when-cross-origin'},
'raw': <urllib3.response.HTTPResponse at 0x119bd1290>,
'url': 'https://redash.brilliant.org/api/queries/8086/results',
'encoding': None,
'history': [],
'reason': 'BAD REQUEST',
'cookies': <RequestsCookieJar[]>,
'elapsed': datetime.timedelta(microseconds=347032),
'request': <PreparedRequest [POST]>,
'connection': <requests.adapters.HTTPAdapter at 0x119bf0910>}
Also, suspiciously, the URL in the response does not contain any query params. So, we tried all possible combinations of using the params
argument and/or the data
argument containing a parameters dictionary, with and without appending p_
to the keys in each place. All of these generated the Missing parameter value for: first_name, last_name, email
error.
Finally, we tried the curl snippet you suggested,
curl --request POST \
--url https://redash.brilliant.org/api/queries/8086/results \
--header 'authorization: Key <API KEY HERE>' \
--data '{
"parameters": {
"first_name": "User first name here",
"last_name": "User last name here",
"email": "User email here",
}
}'
and the output was
{"job": {"status": 4, "error": "Missing parameter value for: first_name, last_name, email"}}