> For the complete documentation index, see [llms.txt](https://docs.eseye.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.eseye.com/api-reference/authentication/request-access-token.md).

# Request access token

Return an OAuth 2.0 bearer token for an API service account.

Tokens are issued using the client credentials grant, which authenticates your service account rather than an individual user.

## Request a token

> Exchange your Base64-encoded service account credentials for an OAuth2 access token.

```json
{"openapi":"3.1.0","info":{"title":"Authentication","version":"1.0.0"},"tags":[{"name":"Authentication","description":"Tokens are issued using the client credentials grant, which authenticates your service account rather than an individual user.\n\nFor a step-by-step walkthrough, see [Generate a bearer token](generate-a-bearer-token)."}],"servers":[{"url":"https://eseye-idp-{env}.auth.{region}.amazoncognito.com","description":"Eseye identity provider","variables":{"env":{"default":"prod","enum":["qan","stage","prod"],"description":"The environment you are working in."},"region":{"default":"eu-west-1","description":"The AWS region your OAuth service is hosted in, for example `eu-west-1` or `us-east-1`."}}}],"paths":{"/oauth2/token":{"post":{"summary":"Request a token","operationId":"get-token","tags":["Authentication"],"description":"Exchange your Base64-encoded service account credentials for an OAuth2 access token.","requestBody":{"required":true,"content":{"application/x-www-form-urlencoded":{"schema":{"type":"object","required":["grant_type","scope"],"properties":{"grant_type":{"type":"string","description":"The OAuth2 grant type. Always `client_credentials`, because your service account authenticates as itself rather than on behalf of a user."},"scope":{"type":"string","description":"The scope of the access token. Always `api/api`."}}}}}},"responses":{"200":{"description":"An access token was issued.","content":{"application/json":{"schema":{"type":"object","required":["access_token","token_type","expires_in"],"properties":{"access_token":{"type":"string","description":"The bearer token to send on every API request."},"token_type":{"type":"string","description":"The type of token issued."},"expires_in":{"type":"integer","description":"The lifetime of the token in seconds. Tokens are issued with a lifetime of one hour."}}}}}},"400":{"description":"The request was rejected. `invalid_client` means the credentials in the `Authorization` header were not accepted.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"string","description":"The reason the request was rejected."}}}}}}},"parameters":[{"name":"Authorization","in":"header","required":true,"description":"Enter `Basic`, a space, and your Base64-encoded `ClientID:ClientSecret` (the only value you need to edit).","schema":{"type":"string","default":"Basic <Base64Encoded(ClientID:ClientSecret)>"}}]}}}}
```

Returns an OAuth 2.0 bearer token for an API service account.

```http
POST /oauth2/token
```

### Endpoint

```
https://eseye-idp-prod.auth.<region>.amazoncognito.com/oauth2/token
```

Replace `<region>` with the AWS region Eseye provided.

### Request headers

| Header          | Value                               | Required |
| --------------- | ----------------------------------- | -------- |
| `Authorization` | `Basic <credentials>`               | Yes      |
| `Content-Type`  | `application/x-www-form-urlencoded` | Yes      |

`<credentials>` is the Base64-encoded form of `<client-id>:<client-secret>`.

### Form parameters

| Parameter    | Value                | Required | Description                        |
| ------------ | -------------------- | -------- | ---------------------------------- |
| `grant_type` | `client_credentials` | Yes      | Authenticates the service account. |
| `scope`      | `api/api`            | Yes      | Requests Eseye API access.         |

### Example request

```bash
curl --request POST \
  --url "https://eseye-idp-prod.auth.eu-west-1.amazoncognito.com/oauth2/token" \
  --user "${ESEYE_CLIENT_ID}:${ESEYE_CLIENT_SECRET}" \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "grant_type=client_credentials" \
  --data-urlencode "scope=api/api"
```

### Successful response

An accepted request returns HTTP `200`:

```json
{
  "access_token": "eyJraWQiOiJhYmMxMjMiLCJhbGciOiJSUzI1NiJ9...",
  "token_type": "Bearer",
  "expires_in": 3600
}
```

Reuse the token until it expires, then request another token.

### Error response

The endpoint returns HTTP `400` when it rejects a request. An `invalid_client` error means the credentials were not accepted.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.eseye.com/api-reference/authentication/request-access-token.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
