Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Total sales and graphql API

Total sales and graphql API

souf
New Member
4 0 0

Hi,

 

In the shopify admin when can go to "Analytics" > "Dashboards" to find the metric "Total sales" as per the following screenshot:

 

Screenshot from 2019-11-26 11-51-11.png

 

I'm working with the GraphQL API to recreate this number. I could achieve it by fetching the Order object (https://help.shopify.com/en/api/graphql-admin-api/reference/object/order) using the field `Order.subtotalPriceSet.shopMoney.amount` to which I deduct the sum of refunds made on the same day. To find those refunds I use the fields `Order.refunds.createAt` and I use the value `Order.refunds.totalRefundSet.shopMoney.amount`.

 

So basically the formula is this one: {total order sales for that day} - {total refunds amounts for that day}.

 

However I have an issue. Let's say that I fetched from API orders for this month, but a refund was made this month for an order made last month. Then I don't have access to this refund. We cannot query list of refunds for a date range from the API. 

 

The question is the following: Is there a way to query transactions made for a given time range and that allows us to calculate total sales as well as gross sales, discounts, refunds, net sales, etc...?

 

Thanks

 

 

Replies 3 (3)

SBD_
Shopify Staff
1831 273 421

Hey @souf,

 

Tender Transactions (REST / GraphQL) might be helpful here. They can be filter on processed_at.

 

Scott | Developer Advocate @ Shopify 

souf
New Member
4 0 0

Hi @SBD_ 

 

Thanks for suggestion, I just gave a quick look, but apparently we cannot associate a tender transaction to an order from the GraphQL API, is that right?

 

In the interim I could manage to use Order's filter `updated_at` to find the refunds I need. I still have some discrepancies because of some refund having 0$ values in the API when it's not the case in the ui for reasons I ignore.

SBD_
Shopify Staff
1831 273 421

Hey @souf,

 

Perhaps you could use the REST API? Tender transactions have an order_id property.

 

03-24-6mo1f-od2e9(1).jpg

Scott | Developer Advocate @ Shopify