This article will run through the steps required to import and save data from your API(s).
For this article, we will assume that you have installed WPGetAPI and have setup your API and the endpoints that you wish to save. View the WPGetAPI Quick Start guide if you need help setting up the API and the endpoint.
Step 1 – Installation & activation
When you purchase the API Importer plugin, you will need to install and activate the plugin – see our installation guide. You also need to have the free WPGetAPI plugin installed.
Step 2 – Setup your endpoint
After installation you will see a new field called Import & Save added to the end of each endpoint. To activate an endpoint for saving, simply select the Yes option and then save the endpoint.
Within your endpoint you must also ensure that the Results Format is set to PHP array data, or XML array data if your API is an XML formatted API.
Step 3 – The API Importer tab
Once you have activated your endpoint(s), visit the API Importer tab and you will see the endpoints that you have activated and there will be 2 fields for each endpoint that are optional to setup.
You’ll also see the Run Importer button which when clicked, will call your endpoints and save the data to an XML file as well as saving the data in your WordPress database.
Your endpoints should first be setup and saved before running the importer.
The Parent Key field
This field is optional. If you simply want to import and save the entire API data, leave this field blank.
If you only want to import some certain data, such as the list of products or items and these items have parent key(s), you can add the key(s) in this field.
Looking at the array below, if you wanted to just import the items that are below the results field, you would simply add results into this field. And if you wanted to just import the first item, you would add results,0 (comma separating the keys).
The Import Interval field
This field is optional. You can set this to No Automatic Imports and the endpoint will only ever be imported and saved by manually pressing the Run Importer button.
Selecting any of the other options will set the importer to run automatically at your chosen interval, which could be 5 Minutes, 30 Minutes, Every Hour, Twice Daily, Daily or Weekly. The importer will run at your chosen interval and will save the endpoint data at this interval, allowing you to keep your API and your imports in sync.
Step 4 – The saved API data
Once the Importer has been run, your XML file will be saved within the location as shown on that endpoint. You can then use that file to run an XML Importer plugin to create posts or WooCommerce products. WP All Import seems to be the most comprehensive option for this.
The endpoint data will also be saved within your WordPress database and to retrieve this, you can use the function as shown within the endpoint. You will need some basic knowledge of PHP to work with this function, otherwise you may need to hire a web developer for this.