Shopify-api-node
Shopify-api-node copied to clipboard
SmartCollection.order Returns 414 if there are too many product IDs
This is partly an issue w/ Shopify's documentation but here's a scenario:
shopify.smartCollection.order(id, { products: [...large product id array...] }
If the # of ids is large enough this will generate a very large URL that cannot be processed and returns a 414 response.
This can be resolved by putting the Product ID array in the body instead of in the URL. This is documented (unofficially) here: https://community.shopify.com/c/Shopify-APIs-SDKs/414-Request-URI-Too-Large-error/td-p/269847/page/2
This can be updated by doing something like this in the package:
SmartCollection.prototype.order = function order(id, params) {
const url = this.buildUrl(`${id}/order`);
return this.shopify.request(url, 'PUT', undefined, params);
};
I've used the above code locally and it resolves the issue.
That being said I recognize that this isn't documented officially so I understand why the product ids are being appended to the URL instead of being added to the body even though appending to the body is more durable. But for a lot of smart collections, the # of product ids will quickly pile up as you add more items to your store. Perhaps adding a flag would be appropriate so you can chose to append the Product IDs to the body if you run into 414 issues?