The WPGetAPI Pro Plugin extends the free WPGetAPI plugin by adding various enhancements to help make working with external API’s even easier. The Pro plugin includes features such as caching, sending data from forms to your API, formatting options and more.
Features at a glance
- Cache API calls – choose the cache time per endpoint
- Dynamic variables – dynamic variables in endpoints, query string, headers and body
- Retrieve nested data – get data from nested, multidimensional arrays
- Base64 encoding – simple method to set a base64 encoded Authorization header
- Format as HTML – format your output as HTML using the shortcode
- Format as a number – format your output as a number using the shortcode
- XML format – as string or as array data
Cache API calls
Adds a field so you can easily set the cache time on any and all endpoints individually. The plugin uses WordPress transients to store the results of your API requests for the amount of time that you set. The cache time can be set differently for each request.
Caching will only work for GET requests and it will not cache if there are error messages. It will only cache successful GET requests returned from your API and will also include headers as well as the body in the saved data.
Dynamic variables allow you to send dynamic data to your API or retrieve dynamic data from your API.
If you need to capture some type of data from your users and send it to an API, the Pro plugin can do this through the use of dynamic variables.
Some examples of using dynamic variables could be:
- send product purchase data to your API that includes user details and purchased items
- a user fills in a form on your website and the form data is sent to your API
Dynamic variables can be used in the query string, endpoints, header or body.
Dynamic variables in query string
Add dynamic variables into the query string of the URL you are sending to the API. This can be done with the template tag or in the shortcode.
The query string is the part of the URL that starts with a question mark and looks something like the bold text in this URL: https://thebaseurl.com/theendpoint/?foo=bar&dynamic_variable=345678
View the docs on how to use Variables in query string.
Dynamic variables in endpoints
Often you will need to add some type of variable within an endpoint to retrieve a particular piece of data.
View the docs on how to use Variables in endpoints.
Dynamic variables in headers
Often you will need to add some type of variable within the headers of your API call.
A common example might be to send an ‘Authorisation’ header or a ‘content-type’ or even a cookie.
View the docs on how to use Variables in headers.
Dynamic variables in body
Variable data can be sent in the Body of your API call (sometimes called POST fields) and it can be sent as plain array data or it can be JSON encoded or URL encoded using the options in the endpoint settings.
A common use for this is to send login details such as a username and password or to send captured form data to an API.
View the docs on how to use Variables in body.
Retrieve nested data
Allows you to step down through multidimensional array data using array keys and indexes to get your data. This works in both the template function and also the shortcode.
View the docs on how to Retrieve Nested Data.
A method to be able to easily set a base64 encoded Authorization header. After enabling the Pro Plugin, you can add your details within the headers like below.
Whatever you wrap in the base64_encode() function will be encoded.
Format data as HTML
The output of your API data can be formatted into HTML by using the ‘format’ attribute in the shortcode.
Firstly ensure that within the endpoint settings, you have the Results Format set to PHP array data and then set the ‘format’ attribute to html as shown below. This will wrap your entire output in a div and will then wrap individual API items in div tags as well.
[wpgetapi_endpoint api_id='quotable' endpoint_id='random' format='html']
For more info, we have an article within our docs on how to format API data into HTML.
Format number in shortcode
If the output of your API is a number, you can format it using the ‘format’ attribute in the shortcode.
Set the ‘format’ attribute to number_format(2) as shown below. This will format the number to have 2 decimal places. You can format from 0 up to any number you choose and will format based on the locale of your site.
[wpgetapi_endpoint api_id='binance' endpoint_id='price_of_coin' keys='price' format='number_format(2)']
This attribute uses the native WordPress function of number_format_i18n as seen here – https://developer.wordpress.org/reference/functions/number_format_i18n/
Adds the option to output the data in XML format, if your API supports that.
We are always happy to help with setup of our plugins – simply put in a support ticket and we will help you get started.