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)