GraphQL - How can I get a list of items returned/exchanged and tie them to original order?

Topic summary

A developer is migrating their consignment vendor payout application from Shopify’s REST API to GraphQL and needs to retrieve return/exchange data linked to original orders.

Initial Challenge:

  • The returns() field only showed quantities returned, not which specific items were returned
  • This information is critical for calculating accurate vendor payouts

Solution Provided:
Query the fulfillmentOrders and returns objects together:

  • Use returns field to access returnLineItems for return details
  • Check fulfillmentOrders to tie returns to specific line items
  • The restocked field indicates inventory status
  • Requires read_orders and read_merchant_managed_fulfillment_orders permissions

Final Implementation:
The developer discovered product information requires navigating: reverseFulfillmentOrders > lineItems > fulfillmentLineItem > lineItem > product

Their workflow now:

  1. Processes orders updated in recent time window
  2. Flags orders with returns into an array
  3. Runs separate queries for flagged orders to retrieve return details

With ~2000 monthly orders and only 5-10 returns, the additional processing overhead is minimal. Issue resolved.

Summarized with AI on November 1. AI used: claude-sonnet-4-5-20250929.

Hi there!

I’m converting my homegrown application from the REST API to GraphQL. One of the thing the application does is load order and return/exchange information in order to produce payout information for our consignment vendors at my wife and I’s retail/online store.

I already have the pulling of the orders working fine. But I need to be able to pull returns/exchanges associated with orders so that I can make adjustments on what we payout to the vendors. I know I can add returns() to my query, but all it seems to give me is the quantity returned… I don’t see a way of telling what item was returned.

Am I missing something?

Thanks

Warwick

Hi @GhoulishMortals ,

To retrieve details about returned or exchanged items and link them to the original order using Shopify’s GraphQL Admin API, you need to query the fulfillmentOrders and return objects. Unfortunately, Shopify’s GraphQL API doesn’t have a direct way to list every individual returned item tied to the original order in one step. However, you can work around this by:

  1. Querying Orders
    Use the order object to retrieve information about the order, including fulfillmentOrders.

  2. Querying FulfillmentOrders
    The fulfillmentOrders field provides details about fulfilled items and their status. From here, you can tie returns to the fulfillment line items.

  3. Querying Returns
    Use the returns field to get details about return requests, including returnLineItems. These items provide information about what was returned.

Example GraphQL Query

query GetOrderReturns($orderId: ID!) {
  order(id: $orderId) {
    id
    name
    lineItems(first: 10) {
      edges {
        node {
          id
          title
          quantity
        }
      }
    }
    fulfillments(first: 10) {
      edges {
        node {
          status
          lineItems(first: 10) {
            edges {
              node {
                id
                quantity
                title
              }
            }
          }
        }
      }
    }
    returns(first: 10) {
      edges {
        node {
          returnLineItems(first: 10) {
            edges {
              node {
                lineItem {
                  id
                  title
                  quantity
                }
                quantity
                restocked
              }
            }
          }
        }
      }
    }
  }
}

Steps:1. Retrieve the orderId: Use a query to fetch orders (orders) or search for specific orders by criteria like name or date range.

  1. Inspect Fulfillments and Returns: Use the fulfillments and returns objects to tie return/exchange data to the original order.
  2. Adjust Payout Calculations: Use the data from returnLineItems to adjust payouts based on returned items.

Important Notes:- Restocked Status: The restocked field in returnLineItems indicates whether the item has been added back to inventory.

  • Paginated Results: Shopify limits the number of results per query (usually 10-50). Use pagination to fetch more data if needed.
  • App Permissions: Ensure your app has read_orders and read_merchant_managed_fulfillment_orders permissions to access these fields.
1 Like

Wow… thank you for the detailed response. I’ll try this out later today!

Thanks again… I did get to play around with this, and for anyone following along… you totally got me in the right direction, but I had to change some of the query because, for instance, the product information is not at the returnLineItems level, it looks like you have to go to reverseFulfillmentOrders > lineItems > fulfillmentLineItem > lineItem > product. I’ve done some tests with different products and different quantities being returned for the same product and this seems to produce the results I’m looking for.

{
    order(id: "gid://shopify/Order/xxx") {
        id
        name
        returns(first:10) {
            edges {
                node {
                    id
                    returnLineItems(first: 10) {
                        edges {
                            node {
                                quantity
                            }
                        }
                    }
                    reverseFulfillmentOrders(first: 10) {
                        edges {
                            node {
                                id
                                lineItems(first: 10) {
                                    edges {
                                        node {
                                            fulfillmentLineItem {
                                                lineItem {
                                                    product {
                                                        id
                                                        title
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

So my code basically loops through orders updated in the last x minutes, processes the orders to populate my shopifyOrders table and if it sees that there are returns for a given order, it adds that order id into an array. That process will already pull any exchanges made. Once the orders have been processed it reads through that array using the query above, and adds the return records. It’ll increase a little to the processing time, but we processes about 2000 orders a month and rarely get more than 5-10 returns in any given month, so it shouldn’t be to much of an overhead.

Thank you again!!