Duplicate products created when using the products API request

2 0 1

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.


Replies 5 (5)

1 0 0

I have been looking into this for a different use case.  I have not seen it in the situation you describe.  I tried using your script there driven with a csv of 50 products with random data. For me, in each try there were no duplicate products created.

Did you manage to figure anything out on your end?

2 0 1

This has been solved, by adding the following to the CURL request: 

curl_setopt($ch, CURLOPT_HEADER, false);

This is weird as this setting has nothing to do with anything related to double processing of a CURL request. However, by adding this to the script, the duplicates stopped being created. 

Shopify Partner
6 0 0

I thought I was seeing the same thing in my PHP app.. tried changing the header, but that didn't work for me.

My issue looked to be in the json_decode(), as the json coming back from the CURL was valid.


For me, I was seeing duplicates with print_r(),

but then used var_dump() and there were no duplicates.

Guessing it was the combination of the json structure and an issue with print_r().


Hey ho.

Shopify Partner
5 0 0

Duplicate products created when using the Shopify API. Is there a solution for this? I've tried both via the Shopify API implementation using the API class and also using cUrl. Both times creates the submitted product twice. Hope there's an update.

Shopify Partner
4 0 1

I'm having duplicate collections when adding them using the Shopify API? I suppose this will be the same cause.