Hi Shopify Community,
I’ve been working on pulling data via the Shopify API and comparing the results with the Shopify dashboard for total sales and order numbers. While most of the data aligns, I’ve noticed a discrepancy between the API and dashboard totals, especially when accounting for partially refunded and voided orders.
Here are the key details:
- Total Sales (API): €356,953.18
- Total Sales (Dashboard): €355,571.59
- Total Orders (API): 5,415
- Total Orders (Dashboard): 5,536
What I’ve Investigated So Far:
- Refunds: I’ve adjusted my API call to account for refunds (both partial and full refunds). This helped explain part of the discrepancy, but the exact difference between the API and dashboard totals still isn’t fully explained.
- Order Status: I’m using status=any in my API call, which should capture all order statuses.
- Time Zone: I’ve ensured that the API request aligns with the store’s time zone (GMT +1:00, Paris).
Despite these adjustments, there are still minor differences that are difficult to trace back to a single metric or calculation. It’s possible that factors such as returns, net sales, shipping costs, tax, and discounts are being handled differently between the API response and the dashboard’s total sales calculation.
My Question:
What is the exact formula that the Shopify dashboard uses to calculate total sales? What I’ve found so far is that there is a refund or partial refund on every discrepancy date, but the refunded amounts alone do not explain the exact difference. Some of the difference can be attributed to taxes and returns, but other parts remain unexplained.
- Does it include gross sales?
- Does it account for refunds (both full and partial)?
- How does it handle shipping and tax?
- Are discounts factored into the total?
Additionally, is there a specific way to handle these variables in the API response to match the dashboard’s numbers more closely?
Code Example:
Here’s a simplified version of my Python code for fetching order data, including handling refunds:
python
Copy code
def fetch_shopify_data(fetch_date):
Date handling and API request code…
total_sales = 0
order_count = 0
for order in response_data[‘orders’]:
order_total_price = float(order[‘total_price’])
Calculate total refund for this order
total_refunds = 0
if ‘refunds’ in order and len(order[‘refunds’]) > 0:
for refund in order[‘refunds’]:
refund_total = sum(float(item[‘subtotal’]) for item in refund[‘refund_line_items’])
total_refunds += refund_total
Subtract refunds from total sales
net_order_total = order_total_price - total_refunds
total_sales += net_order_total
order_count += 1
return total_sales, order_count
Any insights on how to match the API’s total sales and order counts more closely with the dashboard would be greatly appreciated!