Urgent.News

What's breaking now, across thousands of outlets.

Tech

Rebuilding Shopify's Finances summary from the Admin GraphQL API, line by line

In May 2025 Shopify's admin replaced the printed Financial Summary with an on-screen Finances summary. So I built a page that reproduces it from the Admin GraphQL API. Matching Shopify's figures turned out to be mostly a question of definitions and dates, not arithmetic. Money and signs Every amount comes back as shopMoney.amount , a string. scalars/Decimal describes it as "A signed decimal…

In May 2025, Shopify replaced its printed Financial Summary with an on-screen Finances summary. To reproduce this, I created a page that pulls the data from the Admin GraphQL API. The amounts in the API are strings that represent signed decimal numbers with arbitrary precision, serialized as strings. I parse each string into integer minor units, sum the integers, and format the result at the end. The precision varies depending on the currency: 2 for USD, 0 for JPY, and 3 for KWD.

Signs are handled in a specific way. Every reduction, such as discounts, returns, and shipping discounts, is stored as a negative number. This allows all reductions to be summed together with positive values to calculate various figures. Each figure in the Finances report is posted to the date of the event that generated it, using the store's time zone from Shop.ianaTimezone.

The Finances report defines gross sales as the product's selling price multiplied by the ordered quantity, excluding discounts, sales reversals, taxes, shipping, or fees. To calculate gross sales, I sum the LineItem.originalTotalSet over product lines for the sale date. Discounts are calculated as the product discount plus the product's proportional share of a cart-wide discount, obtained from each product line's discountAllocations.

Returns are calculated by adding the line Sales reversals, which include the value of returned products, order cancellations, edits, adjustments to shipping, taxes, fees, and discounts.

Net sales is calculated as gross sales minus discounts minus sales reversals. It does not include shipping charges or taxes. The report provides two different formulas, which I will follow by including duties. However, the Sales report includes duties, while the Finances report does not.

Other details, such as gift cards, tips, and payments, are handled separately. Gift cards are not counted as sales, while tips and payments are reported in their respective sections. The method used to retrieve payment data involves grouping by payment method and calculating net payments, which is the total amount paid minus the total amount refunded.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Monday 5 October →