We are struggling with an issue on the Shopify API. We have a php script that automatically adds products to our Product inventory. After adding 47 products, we end up with 56 products in the API. 8 of the products have been duplicated at random, and two exact copies of these products added into Shopify. The 8 products it duplicates are completely at random - if we delete th 56 products, and readd our 47, the next time we might get 6 duplicates and they are a completely different 6 products to the 8 products that duplicated the previous time.
You can see example of duplicates on our shop, by going to https://mumblebooks.co.uk/search?q=rugby - there are 3 duplicated products on the first page.
Our code is extremely simple:
$url = “https://“.$apikey.”:“.$secret.”@“.$shopdomain.”/admin/products.json";
$data = '{“product”:{“title”:”‘.$productname.’“,“body_html”:”‘.$bodyhtml.’“,“vendor”:”‘.$productproducer;
$data = $data.’“,“product_type”:”‘.$productstreamname.’“,“tags”:”‘.$tags.’",“published_at”: “‘.$timestamp.’”‘;
$data = $data.’,“images”:[‘;
$data = $data.’{“src”: “‘.$primaryimageurl.’”}‘;
$data = $data.’,{“src”: “‘.$secondimageurl.’”}‘;
$data = $data.’,{“src”: “‘.$thirdimageurl.’”}‘;
$data = $data.’]‘;
$data = $data.’,“variants”:[{“barcode”: “‘.$productuniqueid.’”,“fulfillment_service”: “Manual”,“weight”: ‘.$lbweight;
$data = $data.’,“weight_unit”: “lb”,“inventory_management”: “shopify”,“inventory_policy”: “deny”,“inventory_quantity”: 1,“price”: ‘.$listingprice.’,“requires_shipping”: true,“sku”: “‘.$productid.’”}]‘;
$data = $data.’}}';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, [‘Content-Type: application/json’]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
We have played with the code for hours to try to see if there is something in the data. We have added sleep(1); between each insert, in order to give Shopify API time to add the previous product before moving onto the next. We have googled/search forum but can’t find anything. We have tried contacting Shopify directly and they pushed us back to the Forum.
Anyone seen this before? Any ideas of how we can stop the duplicates?
Thanks in advance.