2️Implementing the Get Token API

This API is used to request access permissions from partners to connect and synchronize with the Transaction Sync API (synchronizing balance changes).

POST Get Token

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

Headers

NameValue

Content-Type

application/json

Authorization

Basic Authentication: Base64[username:password]

username and passwordfor this API will be provided by the partner to VietQR.

Body

NameTypeDescription

access_token

String

Bearer Token that you provide to VietQR to access your API Transaction Sync.

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
}

Sample

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class VietQRTokenGenerator {

    public static void main(String[] args) {
        try {
            // URL của API
            URL url = new URL("https://api.vietqr.org/vqr/api/token_generate");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            // Thiết lập phương thức POST
            connection.setRequestMethod("POST");

            // Thiết lập header Authorization
            String auth = "Basic Y3VzdG9tZXItdmlldHFydGVzdC11c2VyMjQ2ODpZM1Z6ZEc5dFpYSXRkbWxsZEhGeWRHVnpkQzExYzJWeU1qUTJPQT09";
            connection.setRequestProperty("Authorization", auth);

            // Gửi request
            connection.setDoOutput(true);
            try (OutputStream os = connection.getOutputStream()) {
                byte[] input = "".getBytes("utf-8");
                os.write(input, 0, input.length);
            }

            // Nhận response
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"));
            StringBuilder response = new StringBuilder();
            String responseLine;
            while ((responseLine = in.readLine()) != null) {
                response.append(responseLine.trim());
            }
            System.out.println("Response: " + response.toString());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

FAQs

How do I grant VietQR access to my API?

You need to create a username and password specifically for VietQR so they can access your Transaction Sync API. Then, share this information with the VietQR team so they can synchronize the data.

Is the login information used by VietQR secure?

VietQR is committed to following strict security protocols. The login information you provide will be encrypted and used solely for data synchronization purposes as agreed upon between both parties.

Are there any limits on the access frequency that VietQR can have to my API?

If there are any limits on access frequency or resources, you should notify the VietQR team in advance so they can adjust the access frequency accordingly and avoid overloading the system.

Can I restrict VietQR's access to a specific part of the API?

Yes, you can configure access rights so that VietQR can only access the necessary endpoints required for data synchronization. This helps ensure the safety and security of your system.

Last updated