Hello, I’ve got a Flow running to Edit some tags when product has variants in-stock/OoS.
But now I wanted to add a change as well to edit ProductVariantInput.inventoryPolicy via API
Request.
I’m not code-literate enough to make this work, I know something is wrong, but I can’t figure out how to get a log or how to fix, so I come to the Community Gurus for assistance.
This is the code I have on the Action.
mutation
{% for variants_item in product.variants %}
{
"input": {
"inventoryPolicy": "DENY",
}
}
{% endfor %}
I found how to provide productID, but, it seems I do need to define Variables, I tried to Get product variant data and in Recent Runs it says it was completed. But now it showed this error.
Ran into exception: Mutation had errors: “Variable $variants of type [ProductVariantsBulkInput!]! was provided invalid value”, “Variable $productId of type ID! was provided invalid value”
Ran into exception: Mutation input evaluated to invalid JSON. Please ensure the input forms valid JSON after Liquid code is run.
Thanks for trying to point me in the right direction. This is what came out in the Failed instance. I don’t know where else I’m supposed to fix anything.
You need to be very detail oriented here. That output does not the match the code you provided. Do you have more code somewhere? If so remove it. Also “variants” should not be capitalized.
Ok, this got weirder for me, there’s two types of mutations in the flow, one to DENY, one to CONTINUE, in separate branches so they would never run twice per flow.
Ran into exception: Mutation had errors: “Variable $input of type ProductVariantInput! was provided invalid value”
Just added another Check to see if inventoryPolicy is already at the desired value, Then do nothing, otherwise run mutation. That seems to have gotten it.
For future readers, this is the final version of the code to affect each variant’s inventoryPolicy within a product. For non-coders like me, you don’t have to enter the mutation information or variables, BUT you HAVE to select the correct mutation. If you’re using GPT to clean your code, don’t, it will add lines and change lower case to upper case here and there. Or do, but delete and format any corrections it makes to comply with the template. And all things before or after a colon : should be in quotes "