get Sales by product variant SKU via API

get Sales by product variant SKU via API

BogdanLyashenko
Visitor
1 0 1

Before some shopify api change, I was able to call API 

with graphQL endpoint and get a report for my application.

https://some-test-store.myshopify.com/admin/api/2023-04/graphql.json

 

 

{
  # "FROM sales SHOW total_sales GROUP BY month SINCE -1y UNTIL today" passes a ShopifyQL query to the GraphQL query.
  shopifyqlQuery(query: "SHOW net_quantity, gross_sales, discounts, returns, net_sales, taxes, total_sales BY product_title, variant_title, variant_sku FROM sales WHERE ((sale_line_type == "product")) SINCE -30d UNTIL today ORDER BY "total_sales" DESC LIMIT 1000") {
    __typename
    ... on TableResponse {
      tableData {
        rowData
        columns {
          # Elements in the columns section describe which column properties you want to return.
          name
          dataType
          displayName
        }
      }
    }
    # parseErrors specifies that you want errors returned, if there were any, and which error properties you want to return.
    parseErrors {
      code
      message
      range {
        start {
          line
          character
        }
        end {
          line
          character
        }
      }
    }
  }
}

 

 

 

Now it does not work. Does anyone know how to get report data via API? 

Replies 2 (2)

ShopifyDevSup
Shopify Staff
1453 238 508

Hey @BogdanLyashenko - thanks for getting in touch. I was able to do a bit of digging and can confirm that "Sales" is no longer a valid dataset/table within ShopifyQL. It is still possible to return sales data based on order data, though. Here's an example query:

{
 shopifyqlQuery(query: "FROM orders SHOW sum(net_sales) GROUP BY week SINCE -3m ORDER BY week") {
   __typename
   ... on TableResponse {
     tableData {
       rowData
       columns {
         name
         dataType
         displayName
       }
     }
   }
       }
     }

 

Here I'm ordering the net sales based on order data grouped by week within the last three months. There's more info here on the data available in the dataset. Hope this helps - let us know if we can clarify anything further on our end. 

 

Al | Shopify Developer Support

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

shadowlessnotes
Tourist
7 0 11

Hi,

Sorry, but that is not a valid solution as you can't return group by variant_sku.