Retrieve variants by SKU

New Member
3 0 0

Hi

I'm using the Shopify REST Admin API to update prices on variants do you know if it's possible to get variants by SKU using the API?

0 Likes
Shopify Partner
1867 182 761

Hi Magnus

Afraid that isn't possible using the REST Admin API since the PUT endpoint for variants requires the variant ID itself in the URI. For what it's worth, also not possible using GraphQL Admin API.

Liked this post? You might also like our fantastic upsell apps Candy Rack and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
Shopify Partner
1867 182 761

Correction, got confused by the title of your question and content. So if you wish to only GET variants by SKU, then you can do that using GraphQL and in another call, do a mutation to update the variant.

query {
  productVariants(first: 1, query: "sku:SKU-123") {
    edges {
      node {
        id
      }
    }
  }
}

Then follow up with the productVariantUpdate mutation:

// mutation
mutation productVariantUpdate($input: ProductVariantInput!) {
  productVariantUpdate(input: $input) {
    userErrors {
      field
      message
    }
    productVariant {
      id
      sku
      price
    }
  }
}

// query variables
{
	"input": {
		"id": "gid:\/\/shopify\/ProductVariant\/000000000001",
		"price": 30.00
	}
}

Sorry for the confusion on my part. Hope this helps!

Liked this post? You might also like our fantastic upsell apps Candy Rack and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
New Member
3 0 0

Thank you very much, this was really helpful :)

0 Likes
New Member
1 0 0

Edit: Solved

0 Likes