# API Get Token

### <mark style="color:green;">`POST`</mark>

```
https://dev.vietqr.org/vqr/api/token_generate
```

**Headers**

<table><thead><tr><th width="225">Name</th><th>Value</th></tr></thead><tbody><tr><td>Content-Type</td><td><code>application/json</code></td></tr><tr><td>Authorization</td><td>Basic Authentication: Base64[<code>username:password</code>]</td></tr></tbody></table>

**Body**

<table><thead><tr><th width="226">Name</th><th width="110">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>access_token</code></td><td>String</td><td><p>It is the Bearer Token provided by VietQR after completing <strong>Step 4</strong>.</p><p>Used to access and generate VietQR payment codes.</p></td></tr><tr><td><code>token_type</code></td><td>String</td><td>It is a “Bearer” type token.</td></tr><tr><td><code>expires_in</code></td><td>String</td><td>The token expiration time is set to 300 seconds by default.</td></tr></tbody></table>

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
    "access_token": "bearer_token_của_đối_tác",
    "token_type": "Bearer",
    "expires_in": 300
}
```

{% endtab %}

{% tab title="400" %}

```json
{
    "status": "FAILED",
    "message": "mã_lỗi_và_mô_tả_lỗi"
}
```

{% endtab %}
{% endtabs %}

***

Reference code

{% tabs %}
{% tab title="cURL" %}

```
curl --location --request POST 'https://dev.vietqr.org/vqr/api/token_generate' \
--header 'Authorization: Basic Y3VzdG9tZXItdmlldHFydGVzdC11c2VyMjQ2ODpZM1Z6ZEc5dFpYSXRkbWxsZEhGeWRHVnpkQzExYzJWeU1qUTJPQT09'
Response:
{
    "access_token": "eyJhbGciOiJIUzUxMiJ9.eyJhdXRob3JpdGllcyI6WyJST0xFX1VTRVIiXSwidXNlciI6IlkzVnpkRzl0WlhJdGRtbGxkSEZ5ZEdWemRDMTFjMlZ5TWpRMk9BPT0iLCJpYXQiOjE3MjEzNzI2MzQsImV4cCI6MTcyMTM3MjkzNH0.D19qvrpYHUgcGjDCXuXXAv3j6lZr6tfmIB0VzdCzAXMJAElGok04sNLysS6PRLdRb0hSgEX5_9KpLjB-xErn-A",
    "token_type": "Bearer",
    "expires_in": 300
}
```

{% endtab %}
{% endtabs %}

***

### Frequently Asked Questions (FAQs)

<details>

<summary>What is the Get Token API used for?</summary>

API Get Token được sử dụng để cấp quyền truy cập vào các dịch vụ của VietQR bằng cách cung cấp một mã token (`access_token`). Mã token này sẽ được sử dụng trong các yêu cầu API khác để xác thực người dùng.

</details>

<details>

<summary>How do I call the Get Token API?</summary>

Bạn cần gửi một yêu cầu POST đến endpoint của API Get Token với thông tin xác thực (username và password) trong phần header. VietQR sẽ cung cấp thông tin này cho bạn sau khi hoàn tất quá trình đăng ký.

</details>

<details>

<summary>How long is the token valid for?</summary>

Token được cấp bởi API Get Token thường có thời gian sử dụng là 300 giây (5 phút). Sau thời gian này, bạn cần gọi lại API để lấy token mới.

</details>

<details>

<summary>What should I do if I receive an error message when calling the Get Token API?</summary>

Kiểm tra lại các thông tin bạn đã gửi, bao gồm username và password. Đảm bảo rằng các thông tin này đúng và vẫn còn hiệu lực. Nếu vấn đề vẫn tiếp diễn, hãy liên hệ với bộ phận hỗ trợ của VietQR để được giúp đỡ.

</details>

<details>

<summary>Why am I receiving an error code when calling the Get Token API?</summary>

Các mã lỗi thường xuất hiện do vấn đề xác thực (sai username hoặc password), yêu cầu không hợp lệ, hoặc lỗi kết nối. Thông báo lỗi sẽ cung cấp chi tiết về nguyên nhân cụ thể, giúp bạn xác định và khắc phục vấn đề.

</details>

<details>

<summary>Which environments can I use the token in?</summary>

Token được cấp có thể sử dụng trên các API của VietQR, tùy thuộc vào môi trường mà bạn đang sử dụng (Test hoặc Prod). Đảm bảo rằng bạn đang gọi API trên đúng môi trường tương ứng.

</details>

<details>

<summary>How can I secure the token after receiving it?</summary>

Token cần được bảo mật như một thông tin nhạy cảm. Không chia sẻ token với bất kỳ ai và lưu trữ nó một cách an toàn. Khi sử dụng token, hãy đảm bảo rằng kết nối của bạn được mã hóa (sử dụng HTTPS) để bảo vệ thông tin khỏi bị lộ.

</details>


---

# Agent Instructions: 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:

```
GET https://api.vietqr.vn/en/vn/api-vietqr-callback/api-get-token-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
