Access to query data from API endpoints

(Jeremy M) #1

Does this plugin present any new API endpoints, i.e. if we wanted to access the data from the query via the API?

Data Explorer Plugin
Get Post Id's of posts that a user liked
API search list user by array of user names
(Jay Pfaffman) #2

Probably so. See

(Simon Cossar) #3

Yes, to get the data from a query you need to know the query’s ID. You can see the ID in the browser’s address bar when you run a query. To make an API request for the data you can do a query like this with CURL, with $api_key and $api_username set to the API credentials from your site and $query_id set to the query’s id.

curl -X POST -d "api_key=$api_key&api_username=$username"$query_id/run

It looks like it’s also possible to create queries through the API. I haven’t tried that yet though.

(Jeremy M) #4

So this works - and is great! Thanks.

Continuing on this line of thinking, is it possible to pass along the params for the query in this? What about also passing in the api_key and api_username so that it is one link and not curl

(Simon Cossar) #5

Yes, it can be done. In a curl request you can pass the parameters as Form Data. Something like this will work:

curl -X POST -F "api_key=$api_key" -F "api_username=simon" -F 'params={"months_ago":"1"}'  http://localhost:3000/admin/plugins/explorer/queries/33/run

(Jeremy M) #6

perfect… what about as part of the link itself and not use curl? Similar to:


How to collect user emails when they sign up
Send email to new users 24 hours after joining
(Simon Cossar) #7

I don’t think that can work. It has to be a POST request. If you’re running the query from another application, the easiest thing to do would be to make the request from your application’s server. That way, you should be able to avoid using curl.