Shopify API - Retrieve full customer order history

jahilldev
Shopify Partner
24 1 3

Hi there,

 

I've recently run into an issue where the following GraphQL query isn't returning orders from a customer that are a few months old. Customers who've ordered recently are getting orders in the response.

 

The weird thing is, in the response I see `numberOfOrders` has the correct value, e.g 2, but the orders array is empty:

 

query CustomerOrders($customerId: ID!) {
  customer(id: $customerId) {
    id
    email
    numberOfOrders
    orders(first: 250) {
      edges {
        node {
          id
          name
        }
      }
    }
  }
}


Is there some limitation I'm hitting? We really need access to a customers full order history for accurate reporting. Is this a scope or app permissions thing?

Any help would be much appreciated

 

All the best

Reply 1 (1)

tim
Shopify Expert
3443 276 1280

Most likely https://shopify.dev/docs/api/admin-graphql/unstable/queries/order#field-order-order:

 

Only the last 60 days' worth of orders from a store are accessible from the Order object by default. If you want to access older orders, then you need to request access to all orders. If your app is granted access, then you can add the read_all_orders scope to your app along with read_orders or write_ordersPrivate apps are not affected by this change and are automatically granted the scope.

If my post is helpful, consider liking it -- it will help others with similar problem to find a solution.
I can be reached via e-mail tairli@yahoo.com