How to Get Customer Information Using GraphQL in Magento 2

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

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

Let’s start!

Step-1:

First of all you must need to Generate Customer Token and pass access 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.

{
  customer {
    firstname
    middlename
    lastname
    suffix
    prefix
    email
    gender
    date_of_birth
    taxvat
    is_subscribed
    created_at
    default_shipping
    default_billing
    addresses {
      firstname
      lastname
      street
      city
      region {
        region_code
        region
      }
      postcode
      vat_id
      country_code
      telephone
      company
    }
  }
}

Output:

{
  "data": {
      "customer": {
        "firstname": "John",
        "middlename": null,
        "lastname": "Deo",
        "suffix": null,
        "prefix": null,
        "email": "johndeo@test.com",
        "gender": null,
        "date_of_birth": null,
        "taxvat": null,
        "is_subscribed": false,
        "created_at": "2021-01-25 16:03:20",
        "default_shipping": "1",
        "default_billing": "1",
        "addresses": [
            {
                "firstname": "Test",
                "lastname": "Test",
                "street": [
                    "Test Address"
                ],
                "city": "Test",
                "region": {
                    "region_code": "NY",
                    "region": "New York"
                },
                "postcode": "12345",
                "vat_id": null,
                "country_code": "US",
                "telephone": "123456789",
                "company": null
            }
        ]
      }
  }
}

In this example, You will get customer information of provided customer access token.


You can use ChromeiQL tool to test and run GraphQL Query in Magento 2.
How to Get Customer Information 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 *