I’m in process of creating a query with data explorer with the APIs. I’m having a hard time finding the actual API call to create a query.
There is an endpoint to run the query /admin/plugins/explorer/queries/<query_id>/run ; however don’t see to create it.
Can anyone help ?
pfaffman
(Jay Pfaffman)
2
1 Like
Thanks for sharing the article of Reverse engineer the discourse API ;
I’ve gone through it and realised that there should be two separate calls need to be made.
First should be, the POST call to /admin/plugins/explorer/queries , which will generate the ID associated with the query.
Secondly, the PUT call needs to be made on /admin/plugins/explorer/queries/id to edit the default query.
But I’m wondering whether there is a provision to create the query(by making the single API call) directly without knowing the ID.
Let me know if that’s possible.
You should be able to make a POST request with the same payload values as PUT.
Did you try?
1 Like
Here is the query which I tried by making POST API call.
curl -X POST https://api-discourse-XXXXXXXXXXXXX/admin/plugins/explorer/queries
-H “Content-Type: multipart/form-data;”
-H “Api-Key: 46811cc32XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”
-H “Api-Username: abcdefg2”
-F ‘query={“name”:“test1234”, “sql”:“SELECT * FROM topics”}’
However, I’m getting an error as below.
{“status”:500,“error”:“Internal Server Error”}%
Not sure what could be wrong.
I think the correct way is the following:
-F 'query[name]=test1234'
-F 'query[sql]=SELECT * FROM topics'
1 Like
Thanks @Arkshine for the help.
It worked…!!
1 Like