# Error when I want to get an access token

**URL:** https://discuss.elastic.co/t/error-when-i-want-to-get-an-access-token/200380
**Category:** Elasticsearch
**Tags:** elastic-stack-security
**Created:** [September 20, 2019, 8:49am UTC](https://discuss.elastic.co/t/error-when-i-want-to-get-an-access-token/200380 "2019-09-20T08:49:50Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![K29](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@K29](https://discuss.elastic.co/u/K29)
#### Post date: [September 20, 2019, 8:49am UTC](https://discuss.elastic.co/t/error-when-i-want-to-get-an-access-token/200380/1 "2019-09-20T08:49:50Z")

</div>

Hello,  
I'm starting to use ElasticSearch and I try to get a token access. For this, I use postman to test this request.

```
method : POST
endpoint : https://myID.europe-west1.gcp.cloud.es.io:9243/_security/oauth2/token
body JSON : { "grant_type" : "client_credentials" }
OR body JSON : { "grant_type" : "password", "username" : "elastic", "password" : "mypasswd" }

```

When I send my request I get this error:

```
"error": {
    "root_cause": [
        {
            "type": "security_exception",
            "reason": "action [cluster:admin/xpack/security/token/create] requires authentication",
            "header": {
                "WWW-Authenticate": [
                    "Bearer realm=\"security\"",
                    "ApiKey",
                    "Basic realm=\"security\" charset=\"UTF-8\""
                ]
            }
        }
    ],
    "type": "security_exception",
    "reason": "action [cluster:admin/xpack/security/token/create] requires authentication",
    "header": {
        "WWW-Authenticate": [
            "Bearer realm=\"security\"",
            "ApiKey",
            "Basic realm=\"security\" charset=\"UTF-8\""
        ]
    }
},
"status": 401
}

```

By default, xpack is installed on ElasticSearch, isn't it? Or, do I need to set more settings?

Thanks for your help.

---

<div class="post-metadata">

### Author: ![K29](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@K29](https://discuss.elastic.co/u/K29)
#### Post date: [September 20, 2019, 11:39am UTC](https://discuss.elastic.co/t/error-when-i-want-to-get-an-access-token/200380/2 "2019-09-20T11:39:51Z")

</div>

The basic authentication in the request header did not seem correct. After correcting the code, I can get an access token. I close this issue...

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 18, 2019, 11:39am UTC](https://discuss.elastic.co/t/error-when-i-want-to-get-an-access-token/200380/3 "2019-10-18T11:39:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
