I have a question that is very similar to (but different from) the question posted here: `DataExplorer::ValidationError: Missing parameter` when running Data Explorer queries with [params] via API .
My query in Data Explorer looks like this:
-- [params]
-- topic_id :topic_id
SELECT * FROM posts WHERE topic_id = :topic_id
This works fine in Data Explorer . Then, when I try and run it via the API I get:
{"success":false,"errors":["DiscourseDataExplorer::ValidationError: Missing parameter topic_id of type topic_id"]}'
Here is my python request:
headers = {
'Content-Type': 'multipart/form-data;',
'Api-Key': API_KEY,
'Api-Username': USERNAME_SYSTEM
}
params = {"topic_id": 398}
response = requests.post(url="[REDACTED]/admin/plugins/explorer/queries/10/run", headers=headers, params=params)
I gather from the error than I cannot pass “topic_id” as a string, but I don’t see how else I can pass it as a key. Any thoughts on this?
1 Like
The parameters are not passed in the URL.
Maybe something like: data={“params”: ‘{“topic_id”:"398"}’
?
I had to try a lot of different alternatives, but this worked:
headers=headers, data={'params': '{\"topic_id\": "398"}'})```
So, the answer is a combination of that prior post (which said you have to escape the quotes when you are sending from a Windows machine and Arkshine's post which says it needs to be passed as data and not as a params kwarg. What I find odd though, is I thought the whole point of the params kwarg in the Python requests module was to pass parameter information.
1 Like
I’m glad it worked!
I tried sending Linux (wsl) or Windows; I don’t have the same issue, and it worked for both.
data = {
'params': '{"topic_id": "3"}'
}
response = requests.post(
url="http://localhost:4200/admin/plugins/explorer/queries/4/run",
headers=headers,
data=data
)
1 Like
system
(system)
Closed
April 14, 2025, 5:25pm
5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.