Magento 2 How To Generate Customer Token Using GraphQL Query

If you want to generate customer token via GraphQL query, you need to perform following steps. You will need GraphQL mutation for any query that requires customer authentication to load data using GraphQL.

generateCustomerToken() mutation is the one we use to create a customer token.

You will need to pass the customer’s email and password fields to the mutation to generate a customer token.

Query to generate customer token:

mutation {
  generateCustomerToken(
   email: "info@magemeta.com"
   password: "test@123"
  ) {
    token
  }
}

Output:

Query will return the output where the token field will be the value of the customer authorization bearer value. You can use this token value in any query/mutation with an authorization header.
Authorization Bearer qwersaeT7r4bv56poiu6ghjnbc6gh54d

{
  "data": {
    "generateCustomerToken": {
      "token": "qwersaeT7r4bv56poiu6ghjnbc6gh54d"
    }
  }
}

Hope this will help you guys!

Leave a Reply