6

I am using magetno 2.3.x and I want to access my account queries provided by Magento_CustomerGraphQl module.

I have installed ChromeiQl to execute GraphQl. I set Site Endpoint as per syntax provided by magento devdocs.

I have generated the customer token using provided type Mutation

type Mutation {
    generateCustomerToken(email: String!, password: String!)
    {
      token
    }
}

But I did not get any way to use this token in ChromiQL as authorization Header.

2 Answers 2

9

Please try this:

Step 1: Get a bearer token: You can get a token by executing the signup mutation in the playground to create a new user. This is the signup mutation I ran:

Request:

mutation {
      generateCustomerToken(email: "[email protected]", password: "password") {
      token
  }
}

Response:

 {
  "data": {
     "generateCustomerToken": {
     "token": "hoyz7k697ubsdsdfsdfsdfsdfv5hcpq92yrtx39i7x"
     }
   }
 }

Step 2: Include the bearer token in your request

Notice there is a text area called HTTP HEADERS at the bottom of the playground. Paste the following code into HTTP HEADERS, replacing your-token-goes-here with the bearer token returned by the server in step 1:

{
   "Authorization": "Bearer zcnj8wd03u19s5fw1yvkprs23du7tfkh"
}

Step 3: Run the post mutation Now that you are including a bearer token in your request you can run the post mutation.

Please check and let me know if you are able to get the response.

2
  • Is it required to add a Bearer token for returning the response?
    – Mohit Rane
    Commented Aug 1, 2023 at 14:33
  • Does this still works? it used to work for me but after the latest updates, not working for me
    – Haris
    Commented Dec 7, 2023 at 13:00
3

The resulting token should be used in subsequent requests in the Authorization header as a Bearer token ex:
Authorization: Bearer {{resultFromGenerateCustomerToken}}

I don't think ChromeQL allows the setting request Headers. If you are on OSX you can use this electron app which give you access to set the headers. https://github.com/skevy/graphiql-app

Additionally, the graphiql included in the PWA Studio includes the same functionality https://github.com/magento-research/pwa-studio

2
  • Thankyou for your response, you are right ChrmeQL does no provide setting for request header so I ended up with GraphiQLFeen. Commented Aug 8, 2019 at 5:24
  • @KapilDevSingh, If you use Altair (chrome extension) then it provides the feature to set request headers in it. I have used it already. Commented Aug 27, 2020 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.