Get all orders and refunds

Hello,
Me and my team are trying to get the following:

  • All orders for a specific time period
  • All refunds for a specfiic time period
  • Match orders and refunds with specific product ID

With the above information we want to construct a daily view of how much each product made per day in net sales (orders - refunds) incluing the amount of units sold.
Also, we want to track partial refunds that potentially do not refer to a speicfic product (if there is such case).

We want to do this via the bulkOperationRunQuery to avoid throttling. We tried to do this by having the bellow example (is not fully complete) but we keep ruinning into the same error “Queries that contain a connection field within a list field are not currently supported.”

mutation GetOrdersBulk {
  bulkOperationRunQuery(
    query: """
    {
      orders {
        edges {
          node {
            id
    				createdAt
    				billingAddress {
    					countryCodeV2
    				}
    				lineItems {
              edges {
                node {
                  id
                  title
    							quantity
    							variant {
    								product {
    									id
                    }
                  }
    							discountedTotalSet {
                    shopMoney {
                      amount
                      currencyCode
                    }
                  }
                }
              }
  					}
            refunds {
              id
              createdAt
              refundLineItems {
                edges {
                  node {
                    lineItem {
                      title
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    """
  ) {
    bulkOperation {
      id
      status
    }
    userErrors {
      field
      message
    }
  }
}

Any guidance on how we can construct the report we want for each day by product and net sales would be greatly appreciated as we’ve been going in loops always running into the same errors.

Many thanks!

Hi Eirinaios,

You may need to break this bulk query into two separate operations (one for orders and one for refunds) and then match orders and refunds by product ID to calculate daily net sales and units sold for each product. The bulkOperationRunQuery mutation only supports querying a single top-level connection field, and doesn’t allow nested connection fields within list fields.