Retrieve Customer Orders list using GraphQL Query in Magento display all the previous orders placed by the customer.
Using Customer Orders Query, get all the order related information with GraphQL.
schema.graphql
file for the orders will be defined at, vendor/magento/module-sales-graph-ql/etc/schema.graphqls
Syntax:
type Customer { orders ( filter: CustomerOrdersFilterInput currentPage: Int = 1 pageSize: Int = 20 ): CustomerOrders }
1.) Generate Customer Token and set Bearer value,
Authorization Bearer {CUSTOMER_TOKEN}
2) Customer Orders GraphQL Query,
query { customer { orders( pageSize: 10 ) { total_count items { id increment_id order_date status shipping_method payment_methods { name } total { grand_total { value currency } } } } } }
pageSize You can set the Page Size value in the query. The default value is 20.
currentPage By Default Current page value is 1. You can set it to a custom value if you have more than 20 records as output.
filter attribute used to filter order by id.
Output:
{ "data": { "customer": { "orders": { "total_count": 3, "items": [ { "id": "Mw==", "increment_id": "000000003", "order_date": "2020-10-30 09:42:59", "status": "Pending", "shipping_method": "Flat Rate - Fixed", "payment_methods": [ { "name": "Check / Money order" } ], "total": { "grand_total": { "value": 203.8, "currency": "USD" } } }, { "id": "NA==", "increment_id": "000000004", "order_date": "2020-11-27 04:36:34", "status": "Processing", "shipping_method": "Flat Rate - Fixed", "payment_methods": [ { "name": "Check / Money order" } ], "total": { "grand_total": { "value": 113, "currency": "USD" } } }, { "id": "NQ==", "increment_id": "000000005", "order_date": "2020-11-27 04:37:27", "status": "Processing", "shipping_method": "Flat Rate - Fixed", "payment_methods": [ { "name": "Check / Money order" } ], "total": { "grand_total": { "value": 113, "currency": "USD" } } } ] } } } }