5️Calling the API Get Token

This is used to retrieve a bearer token for accessing the VietQR payment code generation API.

POST

https://<vietqr-host>/<basepath>/api/token_generate

Headers

Name
Value

Content-Type

application/json

Authorization

Basic Authentication: Base64[username:password]

Body

Name
Type
Description

access_token

String

Bearer Token provided by VietQR to access the VietQR payment code API.

token_type

String

Token type "Bearer".

expires_in

String

Token expiration time. Default is 300 seconds.

Response

{
    "access_token": "bearer_token",
    "token_type": "Bearer",
    "expires_in": 300
}

Code mẫu

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
}

FAQs

What is the API Get Token used for?

The API Get Token is used to grant access to VietQR’s services by providing an access token. This token is then used in subsequent API requests to authenticate the user.

How do I call the API Get Token?

You need to send a POST request to the API Get Token endpoint with the authentication details (username and password) in the header. VietQR will provide this information after you complete the registration process.

How long is the token valid?

The token provided by the API Get Token is typically valid for 300 seconds (5 minutes). After this time, you need to call the API again to obtain a new token.

What should I do if I receive an error when calling the API Get Token?

Double-check the information you submitted, including the username and password. Ensure that these details are correct and still valid. If the issue persists, contact VietQR's support team for assistance.

Why am I getting an error code when calling the API Get Token?

Errors often occur due to authentication issues (such as incorrect username or password), invalid requests, or connection problems. The error message will provide specific details to help you identify and resolve the problem.

In which environment can I use the token?

The token can be used for VietQR APIs, depending on the environment you are using (Test or Production). Ensure that you are calling the API in the appropriate environment.

How can I secure the token once received?

The token should be treated as sensitive information. Do not share it with anyone, and store it securely. When using the token, make sure your connection is encrypted (use HTTPS) to protect the information from being exposed.

Last updated