There are a few setup steps required for the WooCommerce Import plugin, but once it is all set up properly it should be very ‘hands-off’.
This article will run through the steps required to import products from your API and turn these into WooCommerce products.
For this article, we will assume that you have installed WPGetAPI, installed the WooCommerce Import plugin and have setup your API and the endpoint that you will be using. View the Quick Start guide if you need help setting up the API and the endpoint.
Overview
Make sure that the API meets these requirements first. You can also test out this plugin at our demo website: https://wpgetapidemo.site/
All API’s are different and are all structured in slightly different, sometimes fairly quirky ways. We’ve tried to make the import plugin as flexible as possible whilst still being relatively easy to use. Some API’s will be very straightforward to setup, whilst others might need some trial and error to get things right.
There are 5 sections will cover here to get this plugin up and running:
- API Setup
- Product Setup
- API Import
- Field Mapping
- Product Creator
Step 1. API Setup
The first step is to fill in the API Setup section as shown above. But how do we know what to add in these fields?
Test the endpoint
What we add to these fields will depend on how the API is structured, and the best way to find out how your API is structured, is to visit the tab for the API you are using and hit the Test Endpoint button.
Below is the output of the Amazon product API after we hit the Test Endpoint button. It is outputting an array because we have the Results Format set to PHP array data, which is exactly what we want.
Array Key field
Each API item (shown as keys [0], [1], [2] and so on) needs to be on the very top level, but in the example above, the [docs] key is on the first level of the array. So to get the API items onto the top level of the array, we add docs in the Array Key field.
If there was no [docs] here and it was your items ([0], [1], [2]) on the top level, you would leave the Array Key field blank.
Item Key field
Each item we want to import needs to have some sort of unique identifier like an SKU, item ID or product ID. In this case we can use the product_id as our unique identifier and add this to the Item Key field.
Flatten Array field
If the API that you are using has many levels of nested arrays within each item, or the Item Key is within an array, then the Flatten Array option will need to be set to Yes.
Let’s see what happens when an array is flattened using the same product.
Non-Flattened Array
The id that we would use for our Item Key field is within a sub-array, which means it is inaccessible to our plugin.
There are also many levels of nested arrays. These nested sub arrays would only be able to be imported as JSON encoded custom fields, which is not what we would want.
Flattened Array
Below is what the same product looks like with a flattened array. All nested sub arrays move up to the top level and the keys have changed as well.
The ‘id’ key now becomes ‘meta_id’ as it has taken on its parent key of ‘meta’. Any other items within the ‘meta’ array are also prepended with their parent key. This is to avoid conflicts as flattening arrays may end up with similarly named items.
Filter By field
The Filter By field allows you to filter your products so that it will only import the ones you decide on.
You can filter by any key/value pairs like so [meta_id:1] or for multiple you can do [meta_id:1,4,5,6,9] and so on.
More to come…