How to Query ShopifyQL Data via Admin API?

Hello Shopify Devs,

I’m working on integrating ShopifyQL analytics into my Shopify app and want to query data using the Admin API. I’ve seen queries like these in the Shopify Analytics page:

pgsql

CopyEdit

[]: SHOW total_sales OVER month AS over FROM sales SINCE 2020-02-14 UNTIL 2025-02-12 ORDER BY over ASC

q[]: SHOW total_sales BY api_client_title FROM sales SINCE 2020-02-14 UNTIL 2025-02-12 ORDER BY total_sales DESC LIMIT 5

I would like to run similar queries via the Admin API but couldn’t find clear documentation on how to structure the requests.

  • What is the correct API endpoint for ShopifyQL queries?
  • How should I format the GraphQL request to send these queries?
  • Are there any specific permissions required to access this data?

If anyone has experience querying ShopifyQL through the Admin API, I’d appreciate any insights or examples.

Thanks in advance! :rocket:

The ShopifyQL API has been sunset since 2024-07.

1 Like

Hi @Luke Thank you so much your prompt answer.

I’m integrating ShopifyQL analytics into my Shopify app and need to query sales data directly from the Shopify Admin API without storing any data in my app’s database. I came across queries like these in the Shopify Analytics page:

pgsql

CopyEdit

[]: SHOW total_sales OVER month AS over FROM sales SINCE 2020-02-14 UNTIL 2025-02-12 ORDER BY over ASC

q[]: SHOW total_sales BY api_client_title FROM sales SINCE 2020-02-14 UNTIL 2025-02-12 ORDER BY total_sales DESC LIMIT 5

I understand that ShopifyQL queries can be executed via the Admin GraphQL API, but I need some clarification on how to handle large datasets efficiently. My main concerns are:

  1. Handling Large Order Data: My store has more than 50K orders. Using the GraphQL API, I can only fetch 250 orders per request, and paginating through such a large dataset would take too long. Is there a more efficient way to retrieve all order data in a single API call?
  2. Real-Time Data for Analytics: Since I don’t want to store any data in my app database, I need a solution that fetches the entire dataset dynamically whenever users load the analytics page.
  3. Optimized Query Approach: Are there any best practices for structuring ShopifyQL queries to minimize API calls while ensuring we retrieve all necessary
    data in one request?

I’d appreciate any insights or recommendations on how to achieve this efficiently. Looking forward to collaborating and learning from the community.

Thanks in advance! :rocket:

Could you use the bulkOperationRunQuery mutation to fetch all orders instead?

1 Like

Hi @Liam-Shopify
Thank you for your suggestion! I explored using bulkOperationRunQuery, but I noticed that it returns the data as a file, which I then have to process separately. While this approach allows fetching large datasets, I’m facing two critical challenges:

  1. Handling Large Order Data Efficiently – My store has over 50K orders. While paginating through the GraphQL API (250 orders per request) is an option, it would take too long. I was hoping to retrieve all order data in a single API call without excessive processing time.
  2. Real-Time Data for Analytics – Since I don’t want to store any order data in my app database, I need a way to dynamically fetch and display the entire dataset when users load the analytics page. Using bulkOperationRunQuery requires waiting for the process to complete and then downloading the file, which isn’t ideal for real-time analytics.

Is there an alternative solution that allows fetching large datasets efficiently while still enabling real-time analytics? Or is there a way to optimize bulkOperationRunQuery so that it processes and returns structured data without requiring file handling?

Would love to hear any insights or best practices from the community! Thanks in advance. :blush: