How to Generate Customer Token Using GraphQL in Magento 2

Do you want to know how to generate customer token using GraphQL Query in Magento 2?

In this tutorial we are going to show you how to generate customer token using GraphQL Query in Magento 2. If you want to generate customer token using GraphQL Query, you will need to use below mention GraphQL mutation.

Let’s start!

Magento provides generateCustomerToken() mutation which we can use to create a customer token.

Here you will need to pass the customer’s email and password fields to the generateCustomerToken() mutation to generate a customer token.

Generate Customer Token Query:

mutation {
  generateCustomerToken(
   email: "testing@magebeginners.com"
   password: "Test@1234"
  ) {
    token
  }
}

In the above GraphQL query, you can see we have passed email and password of customer which we need to generate token.

Output:

{
  "data": {
    "generateCustomerToken": {
      "token": "a293kq5hmebsq3ai3yo59tbw8ao05l6z"
    }
  }
}

When you run query will get response like above. You can use this token to any query/mutation with an authorization header. See below example.

Authorization Bearer a293kq5hmebsq3ai3yo59tbw8ao05l6z

You can use ChromeiQL tool to test and run GraphQL Query in Magento 2.

How to Generate Customer Token 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 *