# API check giao dịch mới

### 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 **hạn chế** sử dụng [tài khoản demo.](https://developer.casso.vn/english-v2-new/casso-api/api/broken-reference)
* Bạn cần có [API Key](https://developer.casso.vn/english-v2-new/casso-api/chung-thuc/tao-api-key-thu-cong) hoặc [Access token từ Oauth 2.0 của Casso](https://developer.casso.vn/english-v2-new/casso-api/chung-thuc/tich-hop-oauth2) để thiết lập ở trường Authorization HTTP Header.

## Đồng bộ giao dịch mới

<mark style="color:green;">`POST`</mark> `https://oauth.casso.vn/v2/sync`

Đồng bộ giao dịch mới tương ứng với số tài khoản của bạn trong business

#### Headers

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

#### Request Body

| Name          | Type   | Description                                                     |
| ------------- | ------ | --------------------------------------------------------------- |
| bank\_acc\_id | string | Số tài khoản ngân hàng của bạn liên kết trên hệ thống của Casso |

{% tabs %}
{% tab title="200 Sync successfully." %}
{% tabs %}
{% tab title="Đồng bộ giao dịch thành công" %}

```
{
    "error": 0,
    "message": "success",
    "data": null
}
```

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

{% tab title="401 Token sai hoặc hết hạn" %}

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

{% endtab %}
{% endtabs %}

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

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

```javascript
curl --location --request POST 'https://oauth.casso.vn/v2/sync' \
--header 'Authorization: Bearer <"Access token nhận được từ OAuth 2.0 của Casso">' \
--header 'Content-Type: application/json' \
--data-raw '{
    "bank_acc_id": "Số tài khoản ngân hàng cần đồng bộ"
}'
```

{% endtab %}

{% tab title="PHP" %}

```php
$curl = curl_init();

$data = array(
  'bank_acc_id' => 'Số tài khoản ngân hàng cần đồng bộ',
);
$postdata = json_encode($data);

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://oauth.casso.vn/v2/sync",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => $postdata),
  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();

RequestBody formBody = new FormBody.Builder()
  .add("bank_acc_id", "Số tài khoản ngân hàng cần đồng bộ")
  .build();

Request request = new Request.Builder()
  .url("https://oauth.casso.vn/v2/sync")
  .post(formBody)
  .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="info" %}
Sau khi bạn gọi API này, nếu hệ thống của Casso phát hiện có một hoặc nhiều giao dịch mới được đồng bộ thì ngay lúc đó hệ thống của Casso sẽ đẩy một Event chứa các giao dịch mới đó tới [Webhook của bạn đã thiết lập](https://developer.casso.vn/english-v2-new/casso-api/api/thiet-lap-webhook).
{% endhint %}
