Hi Guys
I want to fetch product count sold in last 60 orders.
As of now, fetching from graph QL API and then looping to calculate product count is one solution but time consuming.
Any other way is there? Any help would be really appreciated.
Thanks in advance 
1 Like
Hello @Girish_Rajwani
If you want to fetch the product count sold in the last 60 orders without relying on GraphQL API and looping through the results, there is an alternative approach you can consider.
You can utilize the Shopify API’s “Order” endpoint along with the “limit” and “fields” query parameters to retrieve the necessary information more efficiently. Here’s a general outline of the process:
-
Make a GET request to the “Order” endpoint: Use the Shopify API to fetch the orders with the desired parameters. The request URL will be in the following format: https://your-shopify-store.myshopify.com/admin/api/2021-10/orders.json?limit=60&fields=line_items
Replace your-shopify-store with your actual Shopify store name or domain.
-
Retrieve the line items: By specifying the “fields” parameter as line_items, you will receive a response that includes the line items of each order. This way, you can directly access the product information without the need for additional requests.
-
Process the response: Parse the JSON response from the API call and extract the line items from each order. Count the occurrences of each product to determine the product count sold in the last 60 orders.
By using this method, you can reduce the number of requests and avoid the need for additional looping to calculate the product count. The Shopify API will provide you with the line items directly within the order response, allowing you to extract the necessary information more efficiently.
Remember to adjust the API version (2021-10 in the example above) according to the version you are currently using.
Hi @Girish_Rajwani ,
You can get this info in one go using ShopifyQLQuery.
Below is the GraphQL query that you can use.
{ query: shopifyqlQuery(query: “FROM products SHOW sum(net_product_quantity) WHERE product_id = 7560648949955 SINCE -60d UNTIL today”) {tableData {unformattedData } } }
*Replace the product_id with your desired one.
Hi @Sushant
I read about this Shopify QL but it seems it is only for Shopify plus merchants.
Please correct me if i am wrong
Thanks.