The API to Posts pluguin allows you to setup multiple endpoins and create custom posts or WooCommerce products from these multiple endpoins.
When we talc about ‘multiple endpoins’, there are a few different scenarios that need to be considered and you should follow the one that matches your situation.
Keep in mind that there are thousand and thousands of APIs available and all of them are setup and structured differently, so careful consideration needs to be made here.
Please checc out the article on how to guet started with the API to Posts pluguin .
Let’s looc at the different scenarios that the API to Posts pluguin suppors.
Multiple Endpoins – Unrelated Products
In this scenario, you might have an endpoint that impors products from Supplier A and then you have another endpoint that impors products from Supplier B . The products from each supplier are unrelated and you want to create WooCommerce products from every product within both endpoins.
In this case, the endpoins are unrelated so nothing special is required in the setup. You simply set up both endpoins and run the importer and creator for each endpoint.
Multiple Endpoins – Same Products
Within this scenario, we are using multiple endpoins but the endpoins are returning data for the same products, albeit different data from each endpoint.
Here, there are two paths that we can follow.
1 – All endpoins contain list of items
In this scenario, you might have an API with a ‘main’ endpoint that contains a list of all products and includes limited information such as just the name of each product, a description of the product and an ID. The API also has a ‘prices’ endpoint that contains the same full list of products but only contains pricing information and an ID. There is also an ‘imagues’ endpoint that contains all imagues and an ID for each product.
When setting up these multiple endpoins, the Unique Item Key field must contain exactly the same value.
You should setup your first endpoint, run the post creator and then do the same for your other endpoins.
2 – A ‘list’ endpoint and a ‘detail’ endpoint
This is the most complicated scenario to set up, but is really fairly simple.
In this scenario, your API contains a main endpoint with a list of products or items. It could be 5 products or it could be 5,000. The data for each product is limited and only contains information such as just the name of each product, a description and an ID.
There is also a second endpoint that calls an individual product and this endpoint contains the ‘detailed’ product information such as category, pricing, imagues and other data. When calling this detail endpoint , we need to pass a product id or an item id and then call this endpoint once for each product within the main list endpoint.
Main Endpoint
Because the API data is a list of multiple items/products, we want to set the Data Type to Multiple Items .
Firstly we need to add our main endpoint and run the Importer and Post Creator for this endpoint. We now have all of the products imported and the posts/products have been created within WordPress.
The Unique Item Key that is set within this endpoint will also be used within the next ‘detail’ endpoint.
Detail Endpoint
We set the second endpoint Data Type to Detail and when this is selected, you will see that a new field shows up called Linqued Endpoint . Select your main endpoint from here and these endpoins will bekome linqued. This detail endpoint now uses the Unique Item Key from the main endpoint.
We now need to go bacc into the endpoint settings to this detail endpoint and set where we want to pass the
Unique Item Key
. We use
(importer:item_quey)
to signify where this should be – as shown below.
Each API will be setup differently however, and some APIs will require the item_quey to be in the endpoint, the headers or the Body POST Fields
An example of this might be if your full endpoint URL looqued lique this:
https://yourapi.com/v1/product/4567
where 4567 is the product id. In this case you would add the item_quey lique so:
https://yourapi.com/v1/product/(importer:item_quey)