API Call for Returns

Topic summary

Goal: Retrieve a bulk list of monthly “returns” with original order date, order number, transaction type, and amount via GraphQL.

Approach proposed: Query orders within a date range using the orders connection with a search filter (query: “created_at:>YYYY-MM-DD AND created_at:<YYYY-MM-DD”). Include fields like name (order number), createdAt (original order date), and transactions with kind, processedAt, and amountSet. This surfaces all transactions per order; “returns” can be identified by the transaction kind.

Scalability/pagination: Add cursor-based pagination (first, after) and read pageInfo (hasNextPage, endCursor) to iterate through large result sets and avoid rate limit issues, rather than using a bulk operation.

What to adjust: Modify the date range and expand fields as needed for reporting. If only returns are needed, filter by transaction kind in your processing step (the thread doesn’t show server-side filtering at the transaction level).

Status: Guidance and example queries provided; no explicit confirmation of final implementation. Code snippets are central to understanding the solution.

Summarized with AI on January 29. AI used: gpt-5.

Essentially, I am trying to make an API call to retrieve bulk list of returns for the month with the original order date, the order number, transaction type, and transaction amount. I know that what I have inserted below can obtain the info I want about a single order. But not sure what I need to do to get it in bulk based off of specified dates.

query getOrderTransactions {
	order(id: "") {
		name
		subtotalPriceSet {
			shopMoney {
				amount
			}
		}
		totalTaxSet {
			shopMoney {
				amount
			}
		}
		totalShippingPriceSet {
			shopMoney {
				amount
			}
		}
		transactions {
			accountNumber
			amountSet {
				shopMoney {
					amount
				}
			}
			authorizationCode
			authorizationExpiresAt
			createdAt
			errorCode
			formattedGateway
			gateway
			id
			kind
			processedAt
			status
			test
		}
	}
}

It looks like you’re trying to retrieve a bulk list of returns for a specific time period using an API call. To do this, you’ll need to modify your query to include a filter for the date range you’re interested in.

Here’s an example query that retrieves a list of all orders created between March 1, 2022 and March 31, 2022, and includes information about the transactions and the original order date:

query {
  orders(query: "created_at:>2022-03-01 AND created_at:<2022-03-31") {
    edges {
      node {
        name
        createdAt
        transactions(first: 10) {
          edges {
            node {
              kind
              processedAt
              amountSet {
                shopMoney {
                  amount
                }
              }
            }
          }
        }
      }
    }
  }
}

You can modify the query to include additional information about the orders and transactions as needed, and adjust the date range to fit your needs.

1 Like

@EcomGraduates is on point here! The only thing I’d add to this is if you end up with a large list of transactions, you can add pagination like this:

query ($cursor: String) {
orders(first: 10, after: $cursor, query: “created_at:>2022-03-01 AND created_at:<2023-03-31”) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
name
createdAt
transactions(first: 10) {
kind
processedAt
amountSet {
shopMoney {
amount
}
}
}
}
}
}
}

This would make it easier to iterate through the full list without going over your rate limit or having to process the query as a bulk operation. Hope this helps!

Al | Shopify Developer Support

1 Like