Ad

How Can I Add Item Cost To A Product Variant Using ShopifyAPI?

- 1 answer

I'm trying to programmatically add a couple dozens products to my Shopify shop using the official ShopifyAPI Python SDK, but I can't figure out how to specify the cost of each variant.

This is what I've tried so far:

variant = shopify.Variant()
variant.price = price
variant.option1 = size
variant.inventory_quantity = qty
variant.inventory_management = "shopify"
variant.fullfilment_service = "manual"
variant.requires_shipping = True
variant.sku = sku
variant.taxable = False
variant.inventory_policy = 'deny'
variant.cost = cost
new_product.variants.append(variant)

Naturally, variant.cost doesn't work. How should I do this? Or is it not yet supported?

I'm using ShopifyAPI version 5.1.0, and the API version is 2019-07.

Ad

Answer

You cann't update unit cost with variant update api call, you need to call inventoryItem api to update unit cost.

**Update a unit cost**

PUT /admin/api/#{api_version}/inventory_items/#{inventory_item_id}.json
{
  "inventory_item": {
    "id": 808950810,
    "tory_item": {
    "id": 808950810,
    "cost": "25.00"
  }
}

please refer this link https://help.shopify.com/en/api/reference/inventory/inventoryitem#update-2019-07

Ad
source: stackoverflow.com
Ad