1
votes

Here is the body

{
  "product": {
    "id": 1202316036,
    "title": "cricket bat for sale",
    "variants":[
        {
            "inventory_quantity": 500
        }


        ]
  }
}

This returns the following error

{
  "errors": {
    "base": [
      "The variant 'Default Title' already exists."
    ]
  }
}

But where as the updating the title seems to be working fine. Here is the body

{
  "product": {
    "id": 1202316036,
    "title": "cricket bat for sale"

  }
}

I am sure that PUT header(Content-Type: application/json) are set properly. Because updating title does work. How should I go about updating inventory management

ps: I am using POSTMAN for using shopify API

2
Could you provide all the settings you're using? (headers, etc.) - davids
I don't think there is a problem with header, as I am able to PUT(update) the title - gates

2 Answers

0
votes

So you do need the variant id otherwise Shopify thinks you are creating a new variant. Also your variants need to have been set up for Shopify to manage their inventory. e.g.

  var product = {
  product:{
    id: productId, 
    variants: [
      {
        id:5991257025,
        inventory_management : "shopify",
        inventory_quantity:20
      },
      {
        id:5991257089,
        inventory_management : "shopify",
        inventory_quantity:26
      }
      ]
    }

};
0
votes

I'm not sure if you can do multiple variants per call but to update a single variant's inventory quantity you'd do it like:

var payload = JSON.stringify({
        variant: {
            id: variantId,
            inventory_quantity: qty
        }
    });

and then put that to "https://myshopifydomain/admin/variants/" +variantId + ".json";

possibly all you need to do is add the variant id for each variant you are updating. Your variant ids can be gotten by GETting the json for your items.