Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

How can I edit the SKU of a variant using GraphQL?

Solved

How can I edit the SKU of a variant using GraphQL?

alb3rts
Shopify Partner
5 0 0

I have a problem when trying to update the SKU value of a variant. I am trying to update it using productVariantUpdate, but the "sku" field is not defined in productVariantInput.

Has anyone encountered this issue?
Thanks,
Albert

Accepted Solution (1)

Eric-HAN
Shopify Partner
297 30 32

This is an accepted solution.

Hi, there

The sku field is in the InventoryItem .you could refer to this 

mutation UpdateProductVariantSKU {
  productVariantUpdate(input: {
    id: "gid://shopify/ProductVariant/xxxxxx",
    inventoryItem: {
      sku: "xxxxxxxxx"
    }
  }) {
    productVariant {
      id
      sku
    }
    userErrors {
      field
      message
    }
  }
}

 

EricHAN_0-1721957119472.png

https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/productVariantUpdate

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee

View solution in original post

Replies 4 (4)

Tal19
Shopify Partner
144 27 29

try something like that:

mutation VariantUpdate($input: ProductVariantInput!) {
  productVariantUpdate(input: $input) {
    productVariant {
      id
      sku
    }
    userErrors {
      field
      message
    }
  }
}
Need Shopify Development, Customization, or POS Support? PM Me!

Kyle_liu
Shopify Partner
437 55 80

Hi @alb3rts 

Like this,

mutation {
  productVariantUpdate(input: {id: "gid://shopify/ProductVariant/43729076", position: 1, barcode: "1234", weight: 1.5, weightUnit: KILOGRAMS, requiresShipping: true, sku: "EXAMPLE_SKU", taxable: true, taxCode: "", options: ["M"], inventoryItem: {cost: 19.99}}) {
    productVariant {
      id
      legacyResourceId
      sku
      barcode
      weight
      weightUnit
      inventoryItem {
        id
        legacyResourceId
        requiresShipping
        unitCost {
          amount
        }
      }
      position
      selectedOptions {
        name
        value
      }
      product {
        id
        title
        legacyResourceId
      }
    }
    userErrors {
      field
      message
    }
  }
}

 

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me Email Me Buy Me A Coffee

Eric-HAN
Shopify Partner
297 30 32

This is an accepted solution.

Hi, there

The sku field is in the InventoryItem .you could refer to this 

mutation UpdateProductVariantSKU {
  productVariantUpdate(input: {
    id: "gid://shopify/ProductVariant/xxxxxx",
    inventoryItem: {
      sku: "xxxxxxxxx"
    }
  }) {
    productVariant {
      id
      sku
    }
    userErrors {
      field
      message
    }
  }
}

 

EricHAN_0-1721957119472.png

https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/productVariantUpdate

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
alb3rts
Shopify Partner
5 0 0

Quick and accurate response. Thank you very much.