API Feature Request: UnitCost Summary on Order object.

Highlighted
Tourist
8 0 1

Speaking specifically about the Order entity in the GraphQL API.
https://shopify.dev/docs/admin-api/graphql/reference/object/order


It contains the following summary fields: 
- totalPriceSet
- totalRefundedSet
- totalShippingPriceSet 
- totalTaxSet
 
So if I wanted to calculate the profit for an order, I would do something like this, by fetching the Order via the API.
Revenue = totalPriceSet.shopMoney.amount - totalRefundedSet.shopMoney.amount 
Expenses  = totalShippingPriceSet.shopMoney.amount - totalTaxSet.shopMoney.amount
and finally 
Profit = Revenue - Expenses

However, Expenses is missing a key piece of information, the total Cost of Goods Sold.
 
The only way to get the total cost of goods sold currently, is to iterate the LineItems -> ProductVariant -> InventoryItem, and retrieve the unitCost from the InventoryItem.  
https://shopify.dev/docs/admin-api/graphql/reference/object/inventoryitem
 
What I am suggesting is including the totalUnitCost of all the order's LineItems on the Order object itself, so the true profit of an order can be calculated without the need to traverse any sub objects.

1 Like
Highlighted
Shopify Partner
520 38 109

Out of curiosity, how are you traversing down to get the unitCost amount now? I am trying to do this like below, but the variant always returns a null set. Using the 2020-07 GraphQL API endpoint.

{
  order(id: "gid://shopify/Order/1003877531710") {
    id
    legacyResourceId
    name
    lineItems(first: 5) {
      edges {
        node {
          id
          quantity
          title
          quantity
          originalUnitPriceSet {
            presentmentMoney {
              amount
              currencyCode
            }
          }
          discountedUnitPriceSet {
            presentmentMoney {
              amount
              currencyCode
            }
          }
          variant {
            inventoryItem {
              unitCost {
                amount
                currencyCode
              }
            }
          }
        }
      }
    }
  }
0 Likes
Highlighted
Tourist
8 0 1

Pretty much exactly, what you're doing. For example.

{
  orders(first: 5) {
    edges {
      node {
        id
        legacyResourceId
        lineItems(first: 10) {
          edges {
            node {
              name
              quantity
              variant {
                inventoryItem {
                  unitCost {
                    amount
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

 
I'd assume you to make sure your variants have a unit cost set, it appears to be optional.

0 Likes
Highlighted
Shopify Partner
520 38 109

That was it. Forgot this is a dummy test shop and not all variants had listed cost. Works fine, but like you said you have to drill down a bit to get to the unit cost for each line item.

0 Likes