GraphQL operation productVariantsBulkDelete - How to format JSON and submit with CURL

Solved

GraphQL operation productVariantsBulkDelete - How to format JSON and submit with CURL

TSappguy
Shopify Partner
8 0 11

Hi,

I'm working on updating from REST API to GraphQL. I've been able to do everything so far based on the CURL examples given in the docs.

I need to delete one variant from a product that has many other variants. I was able to do this successfully with productVariantDelete, however that is shown as deprecated, and so I want to do this instead with productVariantsBulkDelete.

However, for productVariantsBulkDelete, there is no CURL example and I'm a little lost. I've tried the 3 variations of the data in the request listed below and all of them produce errors. Can someone help me format this request so it works?


REQUEST DATA:

 

 

{
    "query": "mutation productVariantsBulkDelete($productId: ID!, $variantsIds: [ID!]!) { productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) { product { id } userErrors { field message }}}",
    "variables": {
        "input": {
            "productId": "gid://shopify/Product/7489728872509",
            "variantIds": [
                "gid://shopify/ProductVariant/41701389959229"
            ]
        }
    }
}

 

 

RESPONSE:

 

 

{"errors":[{"message":"Variable $productId of type ID! was provided invalid value","locations":[{"line":1,"column":36}],"extensions":{"value":null,"problems":[{"path":[],"explanation":"Expected value to not be null"}]}},{"message":"Variable $variantsIds of type [ID!]! was provided invalid value","locations":[{"line":1,"column":53}],"extensions":{"value":null,"problems":[{"path":[],"explanation":"Expected value to not be null"}]}}]}

 

 

 

REQUEST DATA:

 

 

{
    "query": "mutation productVariantsBulkDelete($productId: ID!, $variantsIds: [ID!]!) { productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) { product { id } userErrors { field message }}}",
    "variables": {
        "productId": "gid://shopify/Product/7489728872509",
        "variantIds": [
            "gid://shopify/ProductVariant/41701389959229"
        ]
    }
}

 

 

RESPONSE:

 

 

{"errors":[{"message":"Variable $variantsIds of type [ID!]! was provided invalid value","locations":[{"line":1,"column":53}],"extensions":{"value":null,"problems":[{"path":[],"explanation":"Expected value to not be null"}]}}]}

 

 

 

REQUEST DATA:

 

 

{
    "query": "mutation productVariantsBulkDelete($productId: ID!, $variantsIds: [ID!]!) { productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) { product { id } userErrors { field message }}}",
    "input": {
        "productId": "gid://shopify/Product/7489728872509",
        "variantIds": [
            "gid://shopify/ProductVariant/41701389959229"
        ]
    }
}

 

 

RESPONSE:

 

 

{"errors":[{"message":"Variable $productId of type ID! was provided invalid value","locations":[{"line":1,"column":36}],"extensions":{"value":null,"problems":[{"path":[],"explanation":"Expected value to not be null"}]}},{"message":"Variable $variantsIds of type [ID!]! was provided invalid value","locations":[{"line":1,"column":53}],"extensions":{"value":null,"problems":[{"path":[],"explanation":"Expected value to not be null"}]}}]}

 

 

Accepted Solution (1)

tedtate
Shopify Staff
18 2 3

This is an accepted solution.

👋 Hi @TSappguy ,

 

I think the issue is that the variable in your input is misspelled.

On line 5 of your file it should be `variantsIds` not `variantIds`.

 

"variantsIds": [
  "gid://shopify/ProductVariant/41701389959229"
]

View solution in original post

Replies 2 (2)

tedtate
Shopify Staff
18 2 3

This is an accepted solution.

👋 Hi @TSappguy ,

 

I think the issue is that the variable in your input is misspelled.

On line 5 of your file it should be `variantsIds` not `variantIds`.

 

"variantsIds": [
  "gid://shopify/ProductVariant/41701389959229"
]
TSappguy
Shopify Partner
8 0 11

Thank You so Much.  That was it.