Solved

GraphQL operations productDelete and productVariantDelete which is the right JSON format

friendoftheroot
Shopify Partner
45 4 8

Hey,

Please help me to correct the format for the JSONs used in the GraphQL operations productDelete and productVariantDelete.


JSONS are valid and look to me like I have the correct setup for this mutation but somehow the format is not accepted. It seems a different array is expected. Did not find an example.

Please have a look it is much appreciated.
Also it will help the next person struggling with this 🙂

https://shopify.dev/api/admin-graphql/2021-10/mutations/productDelete

 

/*

{"query":"mutation productDelete($input: ProductDeleteInput!) { productDelete(input: $input) {userErrors { field message} }}","variables":{"input":[{"id":"gid://shopify/Product/6881165607118"},{"id":"gid://shopify/Product/6947754475726"}]}

*/

 

 

https://shopify.dev/api/admin-graphql/2021-10/mutations/productVariantDelete

 

 

/*

{"query":"mutation productVariantDelete($id: ID!) { productVariantDelete(id: $id) {userErrors {  field  message}  }}","variables":[{"id":409364442318386},{"id":409364442318386},{"id":409364442318386}]}
	
*/

 

 

Accepted Solution (1)
friendoftheroot
Shopify Partner
45 4 8

This is an accepted solution.

Ok, I have the solution.

These functions do not allow multiple product ids. That's it.

There seems to be no replacement for https://shopify.dev/api/admin-graphql/2021-10/mutations/productDelete

But for the variants there is a bulk version of https://shopify.dev/api/admin-graphql/2021-10/mutations/productDelete , it is this one:
https://shopify.dev/api/admin-graphql/2021-10/mutations/productVariantsBulkDelete

This is how it is fed with data:


{"query":"

mutation productVariantsBulkDelete($productId: ID!, $variantsIds: [ID!]!) {
productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) {
product {
# Product fields
}
userErrors {
field
message
}
}
}

",
"variables":{"input":{"id":"gid://shopify/Product/6881165607118"},[{"id":"gid://shopify/Product/6947754475721"},{"id":"gid://shopify/Product/69477544757262"},{"id":"gid://shopify/Product/6947754475723"}]}

View solution in original post

Replies 4 (4)

friendoftheroot
Shopify Partner
45 4 8

I tried again but I do not find the right format.. unfortunately with graphql you cannot send a get request and find what is needed like in Rest. 😞
It has to be a quite simple solution though.

friendoftheroot
Shopify Partner
45 4 8

Still struggling with this. I would really like to give graphql a go here.
Can someone have a heart and provide an example please.

friendoftheroot
Shopify Partner
45 4 8

This is an accepted solution.

Ok, I have the solution.

These functions do not allow multiple product ids. That's it.

There seems to be no replacement for https://shopify.dev/api/admin-graphql/2021-10/mutations/productDelete

But for the variants there is a bulk version of https://shopify.dev/api/admin-graphql/2021-10/mutations/productDelete , it is this one:
https://shopify.dev/api/admin-graphql/2021-10/mutations/productVariantsBulkDelete

This is how it is fed with data:


{"query":"

mutation productVariantsBulkDelete($productId: ID!, $variantsIds: [ID!]!) {
productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) {
product {
# Product fields
}
userErrors {
field
message
}
}
}

",
"variables":{"input":{"id":"gid://shopify/Product/6881165607118"},[{"id":"gid://shopify/Product/6947754475721"},{"id":"gid://shopify/Product/69477544757262"},{"id":"gid://shopify/Product/6947754475723"}]}

friendoftheroot
Shopify Partner
45 4 8

I hope Shopify will also add productBulkDelete, or someone finds a solution here.