Using Admin API to query product sales with or without ShopifyQL

Using Admin API to query product sales with or without ShopifyQL

alban03
Shopify Partner
1 0 1

Hello Community,

 

ShopifyQL, which can be used with GraphQL to query sales data for products, itself is not depreciated, but the response object is. This seems kind of weird. I understand that this means while ShopifyQL is not depreciated, it essentially is because the response is. There just doesn't seem to be an alternative to using it. 

 

Is there an alternative for getting sales data via GraphQL admin API? 

 

The only other solution I can think of, is querying all orders and filtering the line items for the target product and summing up the sales.

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1453 238 508

Hi @alban03,

 

At this time there's no way to query direct sales data via the Admin API query, though I do know this is a commonly requested feature and I will be sending up feedback on your behalf that you would like to see this added in the near future!

That said, one workaround you can use is querying Orders with a specific product SKU to get a list of all orders that contained that SKU. However it is important to know this does include orders that have refunded or returned the sku in question as well so you will need to keep that in mind when crafting your queries. Here's an example of a query that can retrieve all orders with a specific SKU.
 

{
   orders(first: 10, query: "sku:ABC123"){
       edges{
           node{
               id
           }
       }
   }
}

I hope this helps, and I hope you have a great day 🙂

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog