Get all Orders by a Customer
With the Crystallize Order API, you can retrieve all the orders made by a particular customer. This section will show you how.
Fetch All Orders
In order to fetch all orders by a customer, you’ll need to provide the customer identifier to the query. The query below uses getAll and provides the customerIdentifier argument to it. It then fetches information regarding all the orders the customer has placed until now.
You can slice the list of orders you get back by using the first argument. This argument allows you to fetch only the number of orders you specify. Let's say you only want to grab the first three results. This is how you would do it:
A connection in GraphQL acts as a wrapper for the list of results you’re paginating. Any connection consists of two fields: edges and pageInfo. Take a look at the following query:
The query above contains the following:
- edges: contains a list of OrderConnectionEdge types.
- node: the object containing the information about an order.
- cursor: a string specifying the location of an item in the list.
- pageInfo: this contains fields such as hasNextPage, hasPreviousPage, endCursor, startCursor, and totalNodes.
To apply pagination to the list of orders, use the first argument and the after argument, which is the cursor. The following query fetches the first two items, starting from the cursor value provided to it.