Lấy access token

Access token là JWT dùng để gọi Open API V3. Token sống khoảng 15 phút. Hãy cache và xin lại khi còn dưới 60 giây tới exp.

Tạo App

Vào Casso Open Platform, tạo App để được cấp quyền gọi API, rồi bật các scope Flow mà App được dùng.

Scope Mức Việc được làm
flow:user:read thấp Đọc user, doanh nghiệp và tài khoản gắn với user
flow:account:read thấp Đọc tài khoản ngân hàng
flow:transaction:read thấp Đọc giao dịch
flow:sync:create trung bình Yêu cầu đồng bộ giao dịch mới
flow:webhook:read thấp Đọc webhook
flow:webhook:create trung bình Tạo webhook
flow:webhook:update trung bình Sửa webhook
flow:webhook:delete trung bình Xóa webhook

Organization trên JWT phải trùng đúng một business còn sống. Không thấy, hoặc thấy nhiều hơn một business, API trả HTTP 403.

Đổi token

POST https://openapi.casso.vn/oauth/token

curl -s -X POST 'https://openapi.casso.vn/oauth/token' \
  -H 'Content-Type: application/json' \
  -d '{"app_id":"<app_id>","app_secret":"<app_secret>"}'
{
  "access_token": "<jwt>",
  "token_type": "Bearer",
  "expires_in": 900,
  "issued_at": 1763300000,
  "exp": 1763300900
}

Endpoint token giới hạn 30 request mỗi phút mỗi IP. app_secret chỉ gửi từ backend.

Gọi API

CURL

curl --location --request GET 'https://openapi.casso.vn/flow/v3/userInfo' \
--header 'Authorization: Bearer <access_token>'

PHP

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://openapi.casso.vn/flow/v3/userInfo",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Bearer <access_token>",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
curl_close($curl);

JAVA

OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://openapi.casso.vn/flow/v3/userInfo")
  .get()
  .addHeader("Authorization", "Bearer <access_token>")
  .build();

Response response = client.newCall(request).execute();

Cùng cách này cho API lấy giao dịch, API thiết lập webhook và các API còn lại. Thiếu hoặc sai Bearer thì API trả HTTP 401.