Development discussions around Shopify APIs
Hey @Shopify, I think I found a bug.
When I try to create multiple products with the same title asynchronously only one product gets created and the rest throw a 422 Unprocessable Entity.
const shopify = new Shopify(....); // official node api -> shopify-api-node let products = [ { title: 'Some name', vendor: 'A' }, { title: 'Some name', vendor: 'B' }, { title: 'Some name', vendor: 'C' }, { title: 'Some name', vendor: 'D' } ] for(let product of products){ shopify.product.create(product).then().catch( err => console.error(err) ) }
I think the problem lies with the handle creation, because if I run the same code except with handles defined like this:
let products = [ { title: 'Some name', handle: 'some-name', vendor: 'A' }, { title: 'Some name', handle: 'some-name-1', vendor: 'B' }, { title: 'Some name', handle: 'some-name-2', vendor: 'C' }, { title: 'Some name', handle: 'some-name-3', vendor: 'D' } ]
then it works successfully.
Hi @Patrick_Hughes,
You're correct, it's the handle creation that is causing this. The error I get when attempting this is:
{ "errors": { "handle": [ "has already been taken" ] } }
When no handle is specified, we set the handle as the parameterized title. When two same-titled products are created at the same time, we try to create them with the same handle. One will fail in this case. Otherwise, if there was time between the products being created, we'd append a numerical suffix to the handle if a product with the handle already exists.
I'm curious what your use case is that this acts as a blocker? I can create an issue internally, but I'm not sure it will be a priority.
Andrew | Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit the Shopify Help Center or the Shopify Blog
Hey @Busfox
Thanks for looking into this and explaining what's going on behind the scenes here. It wasn't a blocker for me but it was unexpected. I got around it by placing all existing handles (which I have in the DB) into a lookup, generating a handle on my side, and then running a while loop until the numerical suffix makes the handle unique in the lookup. Another, easier but slower option is to create the products synchronously. The use case is for an epos integration where it's possible to have two products with the same title created at the same time.
As a business owner, have you ever wondered when your customer's first impression of yo...
By Skye Jun 6, 2023We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023