# API thiết lập webhook

## &#x20;Tạo webhook

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

Thực hiện tạo webhook tới server của bạn

#### Headers

| Name          | Type   | Description       |
| ------------- | ------ | ----------------- |
| Authorization | string | chứa Access-Token |

#### Request Body

| Name          | Type    | Description                                                            |
| ------------- | ------- | ---------------------------------------------------------------------- |
| income\_only | boolean | là giá trị được thiết lập để có gửi webhook đối với tiền vào hay không |
| secure\_token | string  | mã bảo mật                                                             |
| webhook       | string  | đường dẫn tới api đầu nhận webhook server của bạn                      |

{% tabs %}
{% tab title="200 Response thông tin webhook đã tạo thành công." %}

```
{
    "error": 0,
    "message": "success",
    "data": {
        "id": 114,
        "channel": "webhook",
        "param1": "https://ten-mien-cua-ban.com/wc/handler-bank-transfer.php",
        "param2": "",
        "send_only_income": 1
    }
}
```

{% endtab %}

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

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

{% endtab %}
{% endtabs %}

```
curl --location --request POST 'https://oauth.casso.vn/v1/webhooks' \
--header 'Authorization: Access token' \
--header 'Content-Type: application/json' \
--data-raw '{
    "webhook": "https://ten-mien-cua-ban.com/wc/handler-bank-transfer.php",
    "secure_token": "@123#abc",
    "income_only": true
}'
```

## &#x20;Chi tiết

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

Xem chi tiết các thông về webhook của bạn theo `webhook Id`

#### Path Parameters

| Name | Type   | Description                        |
| ---- | ------ | ---------------------------------- |
| id   | string | `id webhook` bạn muốn xem chi tiết |

#### Headers

| Name          | Type   | Description    |
| ------------- | ------ | -------------- |
| Authorization | string | `Access-Token` |

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

```
{
    "error": 0,
    "message": "success",
    "data": {
        "id": 111,
        "channel": "webhook",
        "param1": "https://ten-mien-cua-ban.com.vn/wc/handler-bank-transfer.php",
        "param2": "",
        "send_only_income": 1
    }
}
```

{% endtab %}

{% tab title="401 " %}

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

{% endtab %}
{% endtabs %}

```
curl --location --request GET 'https://oauth.casso.vn/v1/webhooks/134' \
--header 'Authorization: Access-Token'
```

## &#x20;Cập nhật &#x20;

<mark style="color:orange;">`PUT`</mark> `https://oauth.casso.vn/v1/webhooks/:id`

Cập nhật các thông tin trong webhook đã được thiết lập trước đó

#### Path Parameters

| Name | Type   | Description  |
| ---- | ------ | ------------ |
| id   | string | `id webhook` |

#### Headers

| Name          | Type   | Description  |
| ------------- | ------ | ------------ |
| Authorization | string | access token |

#### Request Body

| Name          | Type    | Description                                       |
| ------------- | ------- | ------------------------------------------------- |
| income\_only  | boolean | xác nhận gửi webhook tiền vào                     |
| secure\_token | string  | mã bảo mật                                        |
| webhook       | string  | đường dẫn tới đầu api nhận webhook server của bạn |

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

```
{
    "error": 0,
    "message": "success",
    "data": {
        "id": 111,
        "channel": "webhook",
        "param1": "https://webhook-cua-ban.com.vn",
        "param2": "sdf",
        "send_only_income": 1
    }
}
```

{% endtab %}

{% tab title="401 " %}

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

{% endtab %}
{% endtabs %}

```
curl --location --request PUT 'https://oauth.casso.vn/v1/webhooks/111' \
--header 'Authorization: Access-Token' \
--header 'Content-Type: application/json' \
--data-raw '{
    "webhook": "https://ten-mien-cua-ban.com/api/bank",
    "secure_token": "@xyz@123",
    "income_only": "false"
}'
```

## &#x20;Xoá một webhook

<mark style="color:red;">`DELETE`</mark> `https://oauth.casso.vn/v1/webhooks/:id`

Thực hiện xóa một webhook bằng `id webhook` &#x20;

#### Path Parameters

| Name | Type   | Description  |
| ---- | ------ | ------------ |
| id   | string | `id webhook` |

#### Headers

| Name          | Type   | Description    |
| ------------- | ------ | -------------- |
| Authorization | string | `Access-Token` |

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

```
{
    "error": 0,
    "message": "success",
    "data": {
        "id": 111,
        "channel": "webhook",
        "param1": "https://khanh-dep-trai.com.vn",
        "param2": "sdf",
        "send_only_income": 1
    }
}
```

{% endtab %}

{% tab title="401 " %}

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

{% endtab %}
{% endtabs %}

```
curl --location --request DELETE 'https://oauth.casso.vn/v1/webhooks/85' \
--header 'Authorization: Access-Token'
```

## &#x20;Xoá tất cả webhook trong đường dẫn &#x20;

<mark style="color:red;">`DELETE`</mark> `https://oauth.casso.vn/v1/webhooks`

Xóa tất cả các webhook đang tồn tại trong đường dẫn webhook trùng với đường dẫn của bạn *( Nếu đã tạo trước đó rồi thì phải xóa mà đúng không! )*

#### Query Parameters

| Name    | Type   | Description                                       |
| ------- | ------ | ------------------------------------------------- |
| webhook | string | đường dẫn tới đầu api nhận webhook server của bạn |

#### Headers

| Name          | Type   | Description    |
| ------------- | ------ | -------------- |
| Authorization | string | `Access-Token` |

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

```
{
    "error": 0,
    "message": "success",
    "data": [
        {
            "id": 108,
            "channel": "webhook",
            "param1": "https://ten-mien-cua-ban.com/wc/handler.php",
            "param2": "",
            "send_only_income": 1
        },
        {
            "id": 109,
            "channel": "webhook",
            "param1": "https://ten-mien-cua-ban.com/wc/handler.php",
            "param2": "",
            "send_only_income": 1
        },
        {
            "id": 110,
            "channel": "webhook",
            "param1": "https://ten-mien-cua-ban.com/wc/handler.php",
            "param2": "",
            "send_only_income": 1
        },
    ]
}
```

{% endtab %}

{% tab title="401 " %}

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

{% endtab %}

{% tab title="404 " %}

```
{
    "error": 12,
    "message": "Webhook not exists",
    "data": null
}
```

{% endtab %}
{% endtabs %}

```
curl --location --request DELETE 'https://oauth.casso.vn/v1/webhooks?webhook=https://websitecuaban.com/api/webhook' \
--header 'Authorization: Access-Token'
```
