# Get a POS access token

> Exchanges the POS client id and client secret for a short-lived Bearer token.

Source: https://docs.tappay.mn/reference/pos/auth/token/

Exchanges the POS client id and client secret for a short-lived Bearer token with the `client_credentials` grant. Every other POS call sends this token in `Authorization`, the POS API key in `X-API-Key`, and a request [signature](https://docs.tappay.mn/glossary.md#signature).

`POST /api/pos/v1/auth/token`

### Authentication

Secret key (Bearer)

### Request body

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

### Response 200

| Name | Type | Required | Values | Description |
| - | - | - | - | - |
| `access_token` | string | yes | | |
| `token_type` | string | yes | `Bearer` | |
| `expires_in` | integer | yes | | |
| `terminal_source` | string | yes | `REGISTERED`, `REQUEST` | |

### Errors

| Code | Status | Message |
| - | - | - |
| [`POS-001`](https://docs.tappay.mn/errors.md#POS-001) | 401 | The POS client id or client secret is invalid. |

*PosClient gets and refreshes this token for you — the example shows the raw HTTP call.*

```bash title="curl"
curl -sS -X POST "https://sandbox-api.tappay.mn/api/pos/v1/auth/token" \
  -H "Content-Type: application/json" \
  -d '{"grant_type":"client_credentials","client_id":"YOUR_POS_CLIENT_ID","client_secret":"YOUR_POS_CLIENT_SECRET"}'
```

```js title="Node.js"
const res = await fetch('https://sandbox-api.tappay.mn/api/pos/v1/auth/token', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    grant_type: 'client_credentials',
    client_id: 'YOUR_POS_CLIENT_ID',
    client_secret: 'YOUR_POS_CLIENT_SECRET',
  }),
});
console.log(await res.text());
```

```php title="PHP"
<?php
$body = json_encode([
    'grant_type' => 'client_credentials',
    'client_id' => 'YOUR_POS_CLIENT_ID',
    'client_secret' => 'YOUR_POS_CLIENT_SECRET',
]);
$ch = curl_init('https://sandbox-api.tappay.mn/api/pos/v1/auth/token');
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => 'POST',
    CURLOPT_POSTFIELDS => $body,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
    ],
]);
echo curl_exec($ch);
```

```python title="Python"
import json, urllib.request, uuid

req = urllib.request.Request(
    'https://sandbox-api.tappay.mn/api/pos/v1/auth/token',
    data=json.dumps({
        'grant_type': 'client_credentials',
        'client_id': 'YOUR_POS_CLIENT_ID',
        'client_secret': 'YOUR_POS_CLIENT_SECRET',
    }).encode(),
    method='POST',
    headers={
        'Content-Type': 'application/json',
    },
)
print(urllib.request.urlopen(req).read().decode())
```

```json title="Response"
{
  "access_token": "YOUR_POS_ACCESS_TOKEN",
  "token_type": "Bearer",
  "expires_in": 3600,
  "terminal_source": "REGISTERED"
}
```

> **Note:** **POS authentication**
>
> POS calls use a partner credential that TapPay issues for your POS, not a merchant key. Get a token with the client id and client secret, then send `Authorization: Bearer <token>`, `X-API-Key` and `X-TapPay-Request-Signature: sha256=<HMAC>` over the method, path, timestamp and body. The SDK `PosClient` gets and renews the token and signs every request for you.

> **Warning:** **Callbacks are not signed**
>
> TapPay does not sign the POS callback. Never trust its status. Read the [payment](https://docs.tappay.mn/glossary.md#payment) with [Retrieve a POS payment](https://docs.tappay.mn/reference/pos/payments/get.md) (`payments.retrieve` in the SDK) before you hand over goods.

In the [sandbox](https://docs.tappay.mn/glossary.md#sandbox) use the [terminal](https://docs.tappay.mn/glossary.md#terminal) `T-SANDBOX-POS` of the merchant `M-SANDBOX-POS`. For the full flow, read the [POS terminal guide](https://docs.tappay.mn/guides/pos-terminal.md).
