Import bulk products from b2b.msan.hr
In this post we will develop a custom wordpress plugin to import bulk products with their meta data from api url https://b2b.msan.hr/B2BService/HTTP/Product/GetProductsList.aspx in xml format that will give products data in response. For this, we will make curl requests to get data from this url with authentication of api credentials and certificates.
API Introduction:
b2b.msan.hr/B2BService api is one of the formatted api data platform that provides bulk products in a vast range of garments, clothing, grocery etc with their meta data in good format that can be easily used by developers.
Curl Request:
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,"https://b2b.msan.hr/B2BService/HTTP/Product/
GetProductsList.aspx");
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_CAINFO, "/path to/ca.pem");
curl_setopt($ch, CURLOPT_SSLCERT, "/path to/client.pem");
curl_setopt($ch, CURLOPT_SSLKEY, "/path to/key.pem");
curl_setopt($ch, CURLOPT_SSLKEYPASSWD, "{keypswd}");
curl_setopt ($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
Get Prices Curl Request:
As like products we have to make another request to get the latest prices of products by using the same request and credentials as above with a price url as under:
https://b2b.msan.hr/B2BService/HTTP/Product/GetProductsPriceList.aspx”)
Get products specifications Curl Request:
We can get extra specifications data of products by using another url of api with the same curl request as under:
https://b2b.msan.hr/B2BService/HTTP/Product/GetProductsSpecification.aspx
Explanation:
In these curl requests we will get products data, prices and specifications data for these products in the other requests as well. We will have to use required certificates and headers in order to retrieve data that is provided by the api otherwise api will give unauthorizes acess or error page that you are not authorized to get data etc.. so it’s recommended to get your required certificates.