How to Get Customer Order History Using GraphQL in Magento 2

Do you want to know how to get customer’s order history information using GraphQL Query in Magento 2?

In this Magento 2 GraphQL Tutorial, We will show how to get customer’s order history information using GraphQL Query in Magento 2. We will use the {customer} query to get customer’s order history information.

Let’s start!

Step-1:

First of all you must need to Generate Customer Token and pass token in header. See below example.

Authorization Bearer {YOUR_CUSTOMER_TOKEN}

Step-2:

The following example returns a summary of the logged-in customer’s orders history.

query {
  customer {
    orders(
      pageSize: 30
    ) {
      total_count
      items {
        id
        increment_id
        order_date
        shipping_method
        payment_methods {
          name
        }
        total {
          grand_total {
            value
            currency
          }
        }
        status
      }
    }
  }
}

Output:

{
  "data": {
    "customer": {
      "orders": {
        "total_count": 2,
        "items": [
          {
            "id": "100",
            "increment_id": "000000100",
            "order_date": "2021-03-01 11:12:45",
            "shipping_method": "Flat Rate - Fixed",
            "payment_methods": [
              {
                "name": "Check / Money order"
              }
            ],
            "total": {
              "grand_total": {
                "value": 500.00,
                "currency": "USD"
              }
            },
            "status": "Pending"
          },
          {
            "id": "101",
            "increment_id": "000000101",
            "order_date": "2021-03-01 11:15:15",
            "shipping_method": "Flat Rate - Fixed",
            "payment_methods": [
              {
                "name": "Check / Money order"
              }
            ],
            "total": {
              "grand_total": {
                "value": 850.00,
                "currency": "USD"
              }
            },
            "status": "Pending"
          }
        }
      ]
    }
  }
}

In this example, You will get customer’s order history information of provided token.


You can use ChromeiQL tool to test and run GraphQL Query in Magento 2.
How to Get Customer Order History Using GraphQL in Magento 2 Click To Tweet

If you liked this tutorial, then please subscribe to our Newsletter for Magento tutorials. You can also find us on Twitter and Facebook. If you have any problem or would like to add to the discussion, leave a comment below!

You May Also Like

Editorial Staff

About the Author: Editorial Staff

Editorial Staff at the MageBeginners is a team of Magento experts writing about Magento Tutorials, Themes, Extensions, Guides, Tricks and much more...

Leave a Reply

Your email address will not be published. Required fields are marked *