# Get an access token

> Exchanges the client ID and client secret of an OAuth 2.0 system for a short-lived access token.

Source: https://docs.tappay.mn/reference/oauth/token/

A system that signs in with OAuth 2.0 Client Credentials exchanges its client ID and client secret for an access token. Call the API with `Authorization: Bearer <access_token>` until the token expires.

`POST /api/v1/oauth/token` Since 2026-09-27

### Authentication

Secret key (Bearer)

### Request body

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `grant_type` | string | yes | `client_credentials` | |
| `client_id` | string | no | | |
| `client_secret` | string | no | | |
| `scope` | string | no | | |

### Response 200

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `access_token` | string | yes | | |
| `token_type` | string | yes | `Bearer` | |
| `expires_in` | integer | yes | | |
| `scope` | string | no | | |

### Errors

| Code | Status | Message |
| - | - | - |
| [`VAL-001`](https://docs.tappay.mn/errors.md#VAL-001) | 400 | The request failed validation. |
| [`KEY-005`](https://docs.tappay.mn/errors.md#KEY-005) | 401 | This client system is disabled, so the request is not accepted. |
| [`KEY-006`](https://docs.tappay.mn/errors.md#KEY-006) | 401 | The client system's inbound method does not allow this kind of credential. |
| [`KEY-009`](https://docs.tappay.mn/errors.md#KEY-009) | 401 | The client ID or client secret is invalid. |

Try it in the playground: https://docs.tappay.mn/reference/oauth/token/

```bash title="curl"
curl -sS -X POST "https://api.tappay.mn/api/v1/oauth/token" \
  -H "Authorization: Bearer sk_test_YOUR_SECRET_KEY" \
  -H "TapPay-Version: 2026-09-27" \
  -H "Idempotency-Key: $(openssl rand -hex 16)" \
  -H "Content-Type: application/json" \
  -d '{"grant_type":"client_credentials","client_id":"YOUR_CLIENT_ID","client_secret":"YOUR_CLIENT_SECRET"}'
```

```js title="Node.js"
import { TapPay } from '@tappay-mn/node';

const tappay = new TapPay({ apiKey: 'sk_test_YOUR_SECRET_KEY' });
const result = await tappay.oauth.token({
  body: {
    grant_type: 'client_credentials',
    client_id: 'YOUR_CLIENT_ID',
    client_secret: 'YOUR_CLIENT_SECRET',
  },
});
console.log(JSON.stringify(result));
```

```php title="PHP"
<?php
require 'vendor/autoload.php';

use TapPay\TapPay;

$tappay = new TapPay(['apiKey' => 'sk_test_YOUR_SECRET_KEY']);
$result = $tappay->oauth->token([
    'body' => [
        'grant_type' => 'client_credentials',
        'client_id' => 'YOUR_CLIENT_ID',
        'client_secret' => 'YOUR_CLIENT_SECRET',
    ],
]);
echo json_encode($result);
```

```python title="Python"
import json
import tappay

client = tappay.TapPay("sk_test_YOUR_SECRET_KEY")
result = client.oauth.token({
    "body": {
        "grant_type": "client_credentials",
        "client_id": "YOUR_CLIENT_ID",
        "client_secret": "YOUR_CLIENT_SECRET",
    },
})
print(json.dumps(result))
```

```json title="Response"
{
  "access_token": "YOUR_ACCESS_TOKEN",
  "token_type": "Bearer",
  "expires_in": 3600
}
```

Read [Get started](https://docs.tappay.mn/get-started.md) for the authentication methods.
