# API lấy giao dịch

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

Một số lưu ý trước khi bắt đầu với các API liên quan tới webhook:

* 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.](broken://pages/-McjWDNXLnazsGil8Lw0)
* Bạn cần có [API Key](/casso-api/chung-thuc/tao-api-key-thu-cong.md) để thiết lập ở trường Authorization HTTP Header.

## &#x20;Lấy giao dịch ngân hàng &#x20;

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

API này cho phép lấy toàn bộ thông tin giao dịch ngân hàng.

#### 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     | integer | Số thứ tự của trang                                                                     |
| fromDate | string  | Lấy giao dịch bắt đầu từ ngày. Định dạng: YYYY-MM-                                      |

#### Headers

| Name          | Type   | Description                                                               |
| ------------- | ------ | ------------------------------------------------------------------------- |
| Authorization | string | `Bearer <"access token từ Oauth2">` **hoặc** `Apikey <"API key của bạn">` |

{% tabs %}
{% tab title="200 Response chi tiết các giao dịch ngân hà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": [
            {
                "id": 5789,
                "tid": "TF2104152395814062",
                "description": "Khanhnm chuyen tien",
                "amount": -193000,
                "cusum_balance": 1070904,
                "when": "2021-04-15T00:00:00",
                "bankSubAccId": "8007041027107",
                "paymentChannel": "",
                "virtualAccount": "",
                "virtualAccountName": "",
                "corresponsiveName": "",
                "corresponsiveAccount": "",
                "corresponsiveBankId": "",
                "corresponsiveBankName": "",
                "accountId": 733,
                "bankCodeName": "acb_digi"
            },
            {
                "id": 5790,
                "tid": "TF2104152997602811",
                "description": "Chuyen tien nap momo",
                "amount": -350000,
                "cusum_balance": 720904,
                "when": "2021-04-15T00:00:00",
                "bankSubAccId": "8007041027107",
                "paymentChannel": "",
                "virtualAccount": "",
                "virtualAccountName": "",
                "corresponsiveName": "",
                "corresponsiveAccount": "",
                "corresponsiveBankId": "",
                "corresponsiveBankName": "",
                "accountId": 733,
                "bankCodeName": "acb_digi"
            },
        ]
    }
}
```

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

{% tab title="401 Access-Token không đúng hoặc đã hết hạ" %}

```
```

{% 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.
{% endhint %}

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

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

```javascript
curl --location --request GET 'https://oauth.casso.vn/v2/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/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/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 %}

## Lấy chi tiết một giao dịch

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

API cho phép bạn xem chi tiết của một giao dịch ngân hàng.

#### Path Parameters

| Name | Type   | Description                          |
| ---- | ------ | ------------------------------------ |
| id   | number | ID của giao dịch trên hệ thống Casso |

#### Headers

| Name          | Type   | Description                                                |
| ------------- | ------ | ---------------------------------------------------------- |
| Authorization | string | `Bearer` + `access token nhận được từ OAuth 2.0 của Casso` |

{% tabs %}
{% tab title="200 Thông tin chi tiết của 1 giao dịch" %}

<pre><code>{
    "error": 0,
    "message": "success",
    "data": {
        "id": 314344,
        "tid": "TF210702253136879",
        "description": "DH220",
        "amount": -10000,
        "cusumBalance": 389460,
        "when": "2021-07-02T12:50:00",
        "bankSubAccId": "8007041023848",
        "paymentChannel": "",
        "virtualAccount": "",
        "virtualAccountName": "",
        "corresponsiveName": "",
        "corresponsiveAccount": "",
        "corresponsiveBankId": "",
        "corresponsiveBankName": "",
<strong>        "accountId": 733,
</strong>        "bankCodeName": "acb_digi"
    }
}
</code></pre>

{% endtab %}

{% tab title="401 " %}

```
{
    "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/transactions/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/transactions/12",
  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/transactions/12")
  .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 %}

{% hint style="warning" %}
Lưu ý về giới hạn gọi API Danh sách giao dịch:

* Gói **SPONSOR**: 2 yêu cầu/phút
* Gói **PIONEER**: 5 yêu cầu/phút
* Gói **STANDARD**: 20  yêu cầu/phút
  {% endhint %}


---

# 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://developer.casso.vn/casso-api/api/lay-giao-dich.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.
