delete_variants
Permanently delete one or more variants from a given product. Ensure at least one variant remains; Shopify automatically preserves variants in completed orders.
Instructions
Permanently delete one or more variants from a product. Irreversible. Each product must keep at least one variant — Shopify rejects requests that would empty the product (delete the whole product via update_product status:ARCHIVED, or use the admin UI for full deletion). Variants in completed orders are kept-but-hidden by Shopify automatically; the historical record on the order is preserved.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| productId | Yes | Product GID. | |
| variantIds | Yes |
Implementation Reference
- src/tools/variants.ts:214-217 (schema)Schema definition for delete_variants tool input: productId (string) and variantIds (array of strings, 1-100 items).
const deleteVariantsSchema = { productId: z.string().describe("Product GID."), variantIds: z.array(z.string()).min(1).max(100), }; - src/tools/variants.ts:389-416 (handler)Handler for the delete_variants tool. Calls the Shopify GraphQL mutation productVariantsBulkDelete with productId and variantIds, throws on user errors, and returns a confirmation message.
server.tool( "delete_variants", "Permanently delete one or more variants from a product. Irreversible. Each product must keep at least one variant — Shopify rejects requests that would empty the product (delete the whole product via update_product status:ARCHIVED, or use the admin UI for full deletion). Variants in completed orders are kept-but-hidden by Shopify automatically; the historical record on the order is preserved.", deleteVariantsSchema, async (args) => { const data = await client.graphql<{ productVariantsBulkDelete: { product: { id: string } | null; userErrors: ShopifyUserError[]; }; }>(VARIANTS_BULK_DELETE_MUTATION, { productId: args.productId, variantsIds: args.variantIds, }); throwIfUserErrors( data.productVariantsBulkDelete.userErrors, "productVariantsBulkDelete", ); return { content: [ { type: "text" as const, text: `Deleted ${args.variantIds.length} variant(s) from ${args.productId}.`, }, ], }; }, ); - src/tools/variants.ts:389-416 (registration)Registration of the delete_variants tool via server.tool() inside registerVariantTools().
server.tool( "delete_variants", "Permanently delete one or more variants from a product. Irreversible. Each product must keep at least one variant — Shopify rejects requests that would empty the product (delete the whole product via update_product status:ARCHIVED, or use the admin UI for full deletion). Variants in completed orders are kept-but-hidden by Shopify automatically; the historical record on the order is preserved.", deleteVariantsSchema, async (args) => { const data = await client.graphql<{ productVariantsBulkDelete: { product: { id: string } | null; userErrors: ShopifyUserError[]; }; }>(VARIANTS_BULK_DELETE_MUTATION, { productId: args.productId, variantsIds: args.variantIds, }); throwIfUserErrors( data.productVariantsBulkDelete.userErrors, "productVariantsBulkDelete", ); return { content: [ { type: "text" as const, text: `Deleted ${args.variantIds.length} variant(s) from ${args.productId}.`, }, ], }; }, ); - src/tools/variants.ts:103-110 (helper)GraphQL mutation string used by the delete_variants handler to delete variants via Shopify API.
const VARIANTS_BULK_DELETE_MUTATION = /* GraphQL */ ` mutation VariantsBulkDelete($productId: ID!, $variantsIds: [ID!]!) { productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) { product { id } userErrors { field message } } } `;