Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
I have made a program that changes the category of products based on a pre-mapped csv file. The file consists of a product type and taxonomy ID, all the products and are then collected by a query and their product types are compared to the ones on the file, if there's a match on the file, then a mutation is created where that product's category is changed with connecting to the Shopify API. The problem is that its pretty unfeasible for large scale lists of products as it takes about a second per product, so 1000 products becomes 15 minutes. And the majority of that time is the API call itself as I've tested with just the comparison algorithm itself and fake data.
So I am wondering if its possible to apply a mutation to an array of products in one go instead of individually?
This is my mutation code, can i change the input of the productid to an array of ids? Thanks
mutation = """ mutation ProductUpdate($input: ProductInput!) { productUpdate(input: $input) { product { id category { id } } userErrors { field message } } } """ variables = { "input": { "id": product_id, "category": category_id } } headers = {'Content-Type': 'application/json', 'X-Shopify-Access-Token': TokenVar} response = requests.post(g_url, json={'query': mutation, 'variables': variables}, headers=headers)
Hi @mttwTHQ1216,
Shopify does have a the option to run mutations in bulk but it's a little more complicated: you need to create a JSONL files with the variables you want to use, upload that to a temporary location in Shopify, create a 'bulk operation' and then wait for it to complete.
There's some more details in the docs that walk through the whole process.
Also, if in the future you have trouble getting answers here I'd try out the official Shopify dev forums at https://community.shopify.dev/. There's a lot more of the technical GraphQL nitty gritty on those forums.
Best,
Daniel
Learn how to build powerful custom workflows in Shopify Flow with expert guidance from ...
By Jacqui May 7, 2025Did You Know? May is named after Maia, the Roman goddess of growth and flourishing! ...
By JasonH May 2, 2025Discover opportunities to improve SEO with new guidance available from Shopify’s growth...
By Jacqui May 1, 2025