# API lấy thông tin tài khoản ngân hàng

### Trước khi bắt đầu

Một số lưu ý trước khi bắt đầu:

* Một tài khoản [Casso](https://my.casso.vn) đã liên kết một tài khoản ngân hàng. Để test với API này **có thể** sử dụng [tài khoản demo.](https://developer.casso.vn/casso-api/api/broken-reference)
* Bạn cần có [API Key](https://developer.casso.vn/casso-api/chung-thuc/tao-api-key-thu-cong) để thiết lập ở trường Authorization HTTP Header.

## Danh sách tài khoản ngân hàng

## Lấy danh sách các tài khoản ngân hàng

<mark style="color:blue;">`GET`</mark> `https://oauth.casso.vn/v2/accounts`

Truy vấn danh sách các tài khoản ngân hàng đã liên kết

#### Headers

| Name                                            | Type   | Description                                                                                                                |
| ----------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | String | <p><code>Bearer <"access token từ Oauth2"></code> <strong>hoặc</strong> </p><p><code>Apikey <"API key của bạn"></code></p> |

{% tabs %}
{% tab title="200: OK Thành công" %}

```javascript
{
    "error": 0,
    "message": "Successful",
    "data": [
        {
            "id": 123,
            "accountNumber": "8007041027107",
            "accountName": "NGUYEN MINH KHANH",
            "accountType": "",
            "balance": 0,
            "currency": "VND",
            "swift": "",
            "citad": "",
            "serviceType": "personal",
            "bankName": "Timo Plus by Viet Capital Bank",
            "BIN": 970454,
            "bankCodeName": "timoplus",
            "memo": "",
            "connectStatus": 1,
            "beginningSettingDate": "2020-08-01",
            "beginningTxnDate": null,
            "beginningBalance": 0,
            "creditTxnTotal": 546403683,
            "creditTxnAmount": 0,
            "debitTxnTotal": 0,
            "debitTxnAmount": 0,
            "lockSyncDate": null,
            "endingBalance": 0,
            "endingTxnDate": "2023-01-05T00:00:00Z"
        },
        ...
    ]
}
```

{% endtab %}
{% endtabs %}

#### Ví dụ:&#x20;

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

```javascript
curl --location --request GET 'https://oauth.casso.vn/v2/accounts \
--header 'Authorization: Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2"'
```

{% endtab %}

{% tab title="PHP" %}

```php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://oauth.casso.vn/v2/accounts",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);
```

{% endtab %}

{% tab title="JAVA" %}

```java
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://oauth.casso.vn/v2/accounts")
  .get()
  .addHeader("Content-Type", "application/json")
  .addHeader("Authorization", "Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">")
  .build();

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

{% endtab %}
{% endtabs %}

## Chi tiết tài khoản ngân hàng

## Chi tiết tài khoản ngân hàng

<mark style="color:blue;">`GET`</mark> `https://oauth.casso.vn/v2/accounts/:accountId`

Truy vấn chi tiết tài khoản ngân hàng đã liên kết.

#### Path Parameters

| Name                                        | Type   | Description                          |
| ------------------------------------------- | ------ | ------------------------------------ |
| accountId<mark style="color:red;">\*</mark> | Number | Mã định danh của tài khoản ngân hàng |

#### Headers

| Name                                            | Type   | Description                                                                                                                |
| ----------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | String | <p><code>Bearer <"access token từ Oauth2"></code> <strong>hoặc</strong> </p><p><code>Apikey <"API key của bạn"></code></p> |

{% tabs %}
{% tab title="200 Thành công" %}

```
{
    "error": 0,
    "message": "Successful",
    "data": {
        "id": 122,
        "accountNumber": "8007041027107",
        "accountName": "NGUYEN MINH KHANH",
        "accountType": "",
        "balance": 123,
        "currency": "VND",
        "swift": "",
        "citad": "",
        "serviceType": "personal",
        "bankName": "Timo Plus by Viet Capital Bank",
        "BIN": 970454,
        "bankCodeName": "timoplus",
        "memo": "",
        "connectStatus": 1,
        "beginningSettingDate": "2020-08-01",
        "beginningTxnDate": null,
        "beginningBalance": 0,
        "creditTxnTotal": 546403683,
        "creditTxnAmount": 0,
        "debitTxnTotal": 0,
        "debitTxnAmount": 0,
        "lockSyncDate": null,
        "endingBalance": 0,
        "endingTxnDate": "2023-01-05T00:00:00Z"
    }
}
```

{% endtab %}

{% tab title="401 Unauthorized" %}

```
{
    "error": 401,
    "message": "Unauthorized Access",
    "data": null
}
```

{% endtab %}
{% endtabs %}

#### Ví dụ:&#x20;

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

```javascript
curl --location --request GET 'https://oauth.casso.vn/v2/accounts/123 \
--header 'Authorization: Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2"'
```

{% endtab %}

{% tab title="PHP" %}

```php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://oauth.casso.vn/v2/accounts/123",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);
```

{% endtab %}

{% tab title="JAVA" %}

```java
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://oauth.casso.vn/v2/accounts/123")
  .get()
  .addHeader("Content-Type", "application/json")
  .addHeader("Authorization", "Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">")
  .build();

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

{% endtab %}
{% endtabs %}

## Danh sách giao dịch ngân hàng

## &#x20;Danh sách giao dịch của một tài khoản ngân hàng

<mark style="color:blue;">`GET`</mark> `https://oauth.casso.vn/v2/accounts/:accountId/transactions`

Truy vấn danh sách giao dịch ngân hàng của một tài khoản đã liên kết.

#### Path Parameters

| Name                                        | Type   | Description            |
| ------------------------------------------- | ------ | ---------------------- |
| accountId<mark style="color:red;">\*</mark> | Number | Mã định danh tài khoản |

#### Query Parameters

| Name     | Type   | Description                                                                             |
| -------- | ------ | --------------------------------------------------------------------------------------- |
| sort     | String | Sắp xếp tăng hoặc giảm dần dựa theo thời gian của giao dịch. Mặc định là ASC(tăng dần). |
| pageSize | String | Số lượng giao dịch trên một trang                                                       |
| page     | Number | Số thứ tự của trang                                                                     |
| fromDate | String | Lấy giao dịch ngày bắt đầu. Định dạng: YYYY-MM-DD                                       |
| toDate   | String | Lấy giao dịch ngày kết thúc. Định dạng: YYYY-MM-DD                                      |

#### Headers

| Name                                            | Type   | Description                                                                                                                |
| ----------------------------------------------- | ------ | -------------------------------------------------------------------------------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | String | <p><code>Bearer <"access token từ Oauth2"></code> <strong>hoặc</strong> </p><p><code>Apikey <"API key của bạn"></code></p> |

{% tabs %}
{% tab title="200 Thành công" %}
{% tabs %}
{% tab title="Response theo page" %}

```
{
    "error": 0,
    "message": "success",
    "data": {
        "page": 4,
        "pageSize": 10,
        "nextPage": 5,
        "prevPage": 3,
        "totalPages": 35,
        "totalRecords": 341,
        "records": [
            {
                "privateId": 199,
                "reference": "TF2104042",
                "bookingDate": "2021-04-04",
                "transactionDate": "2021-04-04",
                "transactionDateTime": "2021-04-04T21:10:00Z",
                "amount": -1000000,
                "description": "RUT TM TU ATM",
                "runningBalance": 23502022,
                "virtualAccountNumber": "",
                "virtualAccountName": "",
                "paymentChannel": "",
                "counterAccountNumber": "",
                "counterAccountName": "",
                "counterAccountBankId": "",
                "counterAccountBankName": ""
            },
            ...
        ]
    }
}
```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="401 Unauthorized" %}

```
```

{% endtab %}
{% endtabs %}

#### Chi tiết các tham số

| Tham số        | Mô tả                                                                                    | Gá trị mặc định |
| -------------- | ---------------------------------------------------------------------------------------- | --------------- |
| ***fromDate*** | Thời gian bắt đầu bạn muốn lấy giao dịch                                                | 7 ngày gần nhất |
| **toDate**     | Thời gian kết thúc bạn muốn lấy giao dịch                                                | Hôm nay         |
| ***page***     | Số thứ tự trang                                                                          | 1               |
| ***pageSize*** | Số giao dịch trên một trang                                                              | 10              |
| ***sort***     | Sắp xếp giao dịch, các giá trị gồm: ASC, DESC. Với ASC là tăng dần còn DESC là giảm dần. | ASC             |

{% hint style="info" %}

* Nếu tham số nào không tồn tại thì sẽ lấy giá trị mặc định.
* Xem chi tiết các trường của một giao dịch, [xem chi tiết](https://developer.casso.vn/casso-api/api/broken-reference)
  {% endhint %}

#### Ví dụ:&#x20;

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

```javascript
curl --location --request GET 'https://oauth.casso.vn/v2/accounts/123/transactions?fromDate=2021-04-01&toDate=2022-07-05&page=4&pageSize=20&sort=ASC' \
--header 'Authorization: Apikey <API Key của bạn> hoặc Bearer <access token từ OAuth2>'
```

{% endtab %}

{% tab title="PHP" %}

```php
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://oauth.casso.vn/v2/accounts/123/transactions?fromDate=2021-04-01&page=4&pageSize=20&sort=ASC",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Authorization: Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">",
    "Content-Type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);
```

{% endtab %}

{% tab title="JAVA" %}

```java
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
  .url("https://oauth.casso.vn/v2/accounts/123/transactions?fromDate=2021-04-01&page=4&pageSize=20&sort=ASC")
  .get()
  .addHeader("Content-Type", "application/json")
  .addHeader("Authorization", "Apikey <"API Key của bạn"> hoặc Bearer <"access token từ OAuth2">")
  .build();

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

{% endtab %}
{% endtabs %}
