Supporting product cost

Shopify has launched the ability for merchants to record the cost of product variants, track profit margins, and report on product performance. Merchants have access to a new Cost per item field when editing variant pricing. They can bulk update product costs by importing a product CSV file, or by using the product bulk editor. We have also introduced product cost within analytics, including the addition of new Profit margin and Gross profit reports. To learn more about per-item cost, see Product details.

This guide explains the changes associated with product cost and how to update your app so that it supports the new feature. Updating your app to read and write product cost provides incredible value to merchants by enabling them to better understand their business right from the Shopify admin.

Throughout this guide, there are example requests and responses that use both our REST Admin API and GraphQL Admin API.

Changes to Shopify resources

To facilitate the product cost feature, we have added a new writable cost property to the InventoryItem resource. This property allows apps to set and retrieve an inventory item's cost.

Retrieve an inventory item's cost

Creating variants with an associated cost

When creating a new product or variant, you can associate a cost using the GraphQL Admin API. The productCreate and productVariantCreate mutations allow you to pass an inventoryItem block on the variant, enabling you to set a cost. As with many mutations, as long as you remain within your app's call limit, you can create multiple products and variants in one request.

Create a product with a single variant and an associated cost

Mutation

{
  mutation createProduct($input: ProductInput!) {
    productCreate(input: $input) {
      userErrors {
        field
        message
      }
      product {
        id
      }
    }
  }
}

Variables

{
  "input": {
    "title": "Product test",
    "variants": [{
      "title": "Variant test",
      "options": "Red",
      "price": "55.00",
        "inventoryItem": {
        "cost": "25.00"
      }
    }]
  }
}

Create a product with multiple variants and associated costs

Mutation

{
  mutation createProduct($input: ProductInput!) {
    productCreate(input: $input) {
      userErrors {
        field
        message
      }
      product {
        id
      }
    }
  }
}

Variables

{
  "input": {
    "title": "Product test",
    "variants": [{
      "title": "Variant test 1",
      "options": "Red",
      "price": "55.00",
        "inventoryItem": {
        "cost": "33.00"
      }
    },
    {
      "title": "Variant test 2",
      "options": "Blue",
      "price": "55.00",
        "inventoryItem": {
        "cost": "33.00"
      }
    }]
  }
}

Update a cost

How can I get help?

If you have questions about implementing product cost in your app, then visit the Shopify forums to get help from the Shopify community.

Sign up for a Partner account to get started.

Sign up