Query Builder REST API Query Type
This overview will describe all the Query Builder’s REST API Query type settings, which is part of the JetEngine plugin.
JetEngine Listing Grid functionality, Tables, and Charts Builders allow you to display the items received via the REST API Endpoint on the front end. However, it doesn’t allow you to query the results. Query Builder fixes that issue. The REST API Query Type gives you the opportunity to create a query of items obtained via the REST API Endpoint.
How to Set Up REST API Query Type
For example, we got the REST API Endpoint from the Custom Content Type with items containing information about movies.
Proceed to JetEngine > Query Builder and click on the “Add New” button. Name a new query and select the “REST API Query” Query Type.
After that, you will see two features of the REST API Query:
- From Endpoint. In this drop-down menu, you will see the list of all Endpoints you created for the website. Choose the one you need;
- Query. This is the section that allows you to create a query. Insert the name of the meta field to the Key bar and afterward type the value to the Value text area. If the value of the key meta field is equal to the value in the Value bar, the item will be added to the list.
As a Value, you can also select one of the macros from the list. Learn more about them from our Macros Guide.
For instant, you could enter the author ID meta field name as the Key and “Current user ID” macros as the Value. So the user will see only the items of his authorship on the page.
For a start, we have created a query without keys and values.
Dynamic Table based on this query shows all items.
Open the API Endpoint URL in your browser. You could use any code editor to organize items like that.
On this screenshot, the black text areas are keys that are meta fields. The green text areas are values.
For example, we have chosen the “contentRating” key and the “R” value.
Then, we have created the Dynamic Table with this query. As we have set up the query, it shows only movies with the R content rating.
If you add a new Key and Value to the query, you can narrow down the result. E. g., we have entered the “genres” key and the “Horror” value.
And now, the table shows only two items with the Horror and R values.
REST API Query with 3rd Party API
There should be no problem to query REST API Endpoint, which has been gotten from JetEngine Custom Content Type, such as one with movies we have queried before. But REST API Query doesn’t work with all APIs.
For instant, we have a REST API data table demo based on IMDb API. You can create a similar table with the same API gotten from the IMDb API documentation, but you won’t be able to query it.
That’s because when you add keys and values to the query, they appear after a question mark “?” in the endpoint. In other words, IMDb API has a path parameters type. Query string parameters type for APIs is required for the Query Builder.
However, you can query IMDb items directly on the IMDb API documentation page.
That’s all. You now learned how to configure REST API Query, use keys and values, and what 3rd party APIs are suitable for the JetEngine Query Builder.