The WPGetAPI Pro Plugin extends the free WPGetAPI plugin by adding various enhancements to help make connecting to external API’s even easier.
Features at a glance
- Caching of API calls – choose the cache time per endpoint
- Base64 encoding – simple method to set a base64 encoded Authorization header
- Format number in shortcode – easily format your output if it’s a number
- XML format – as string or as array data
- Retrieve nested data – easily get data from nested, multidimensional arrays
- Variables in query string – send unlimited variables in the query string
- Variables in endpoints – send unlimited variables in your endpoints
- Variables in headers – send unlimited variables in your headers
- Send variables in body – send variable data in POST fields in the body
Caching of 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.
Base64 encoding
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 number in shortcode
Adds a new attribute to the shortcode called ‘format’. Setting this to number_format(2) as shown below 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' debug='false' 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/
XML Format
Adds the option to retrieve data in XML format.
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.
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/?query=string&something=else&another=query
View the docs on how to use Variables in Query String.
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.
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.
Send 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 logins such as a username and password.
View the docs on how to use Send Data in Body.
You can test out the free version of our API plugin here, available in the WordPress plugin directory.