skip to Main Content

I am trying to update shopify variant’s inventory quantity by SKU,
but i am not getting how to do it by there dev docs,

here is what i’ve done,

i installed https://github.com/Shopify/shopify_python_api and written below code, and the code is working fine, but not sure how to get variant by sku and update its available quantity on shopify.

shop_url = "https://%s:%[email protected]/admin/api/%s" % (API_KEY, PASSWORD, API_VERSION)
shopify.ShopifyResource.set_site(shop_url)
shop = shopify.Shop.current()
product = shopify.Product.find(4398162804809)
print(product)

2

Answers


  1. Chosen as BEST ANSWER

    i used graphql query and it returns me the following details,

    {'data': {'productVariants': {'edges': [{'node': {'id': 'gid://shopify/ProductVariant/31281648828489'}}]}}, 'extensions': {'cost': {'requestedQueryCost': 3, 'actualQueryCost': 3, 'throttleStatus': {'maximumAvailable': 1000.0, 'currentlyAvailable': 997, 'restoreRate': 50.0}}}}
    

    Now i am looking for exact graphql query which should return me the exact product id and variant id.


  2. SKU’s are not unique values. You can have all of your variants to have the same SKU which is not usable. That’s why you can’t update them by SKU, but only by ID.

    There is no way to get variants by SKU with the REST API if I’m not mistaken.

    For that you will need to look into GraphQL:

    query {
      productVariants(first: 1, query: "sku:YOUR_SKU") {
        edges {
          node {
            id
          }
        }
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search