# WebHook

## Create WebHook Client

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

```php
use BlockSDK;

$blockSDK = new BlockSDK("YOU_TOKEN");
$webhookClient = $blockSDK->createWebHOOK();

or

$webhookClient = BlockSDK::createWebHook("YOU_TOKEN");
```

{% endtab %}
{% endtabs %}

## Object

### WebHook

| Name            | Type     | Content                                                |
| --------------- | -------- | ------------------------------------------------------ |
| id              | int      | WebHook Unique Number                                  |
| category        | string   | Cryptocurrency Address Types(btc,bch,ltc,dash,eth,xmr) |
| address         | string   | Cryptocurrency Address                                 |
| callaback       | string   | Address to request when event occurs (http, https)     |
| callback\_error | int      | Callback Address Call Error Count                      |
| create\_at      | datetime | Webhook creation datetime                              |

### WebHookResponse

| Name        | Type     | Content                              |
| ----------- | -------- | ------------------------------------ |
| webhook\_id | int      | WebHook Unique Number                |
| category    | string   | Cryptocurrency symbol                |
| address     | string   | Cryptocurrency address               |
| status      | int      | Callback Address Call Response Code  |
| event       | string   | Trading event(confirmed,unconfirmed) |
| tx\_hash    | string   | Transaction hash                     |
| datetime    | datetime | Event Date Time                      |

### CallbackRequest

| Name        | Type   | Content                                             |
| ----------- | ------ | --------------------------------------------------- |
| webhook\_id | int    | ID issued when creating web hook                    |
| event       | string | Event type (confirmed or unconfirmed)               |
| category    | string | Coin Type (btc or bch or ltc or eth or dash or xmr) |
| address     | string | Cryptocurrency address where the event occurred     |
| tx\_hash    | string | Transaction hash                                    |
| api\_token  | string | User's api token                                    |

## ListHook

<mark style="color:blue;">`GET`</mark> `https://api.blocksdk.com/v1/hook`

#### Query Parameters

| Name   | Type   | Description                 |
| ------ | ------ | --------------------------- |
| offset | number | WebHook List Offset         |
| limit  | number | Number of WebHook to import |

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

```javascript
[
    {
        "id":9,
        "category":"btc",
        "address":"17AJUKEaJPhrqSRwZtr3usw9Na6f8SHMqG",
        "callback":"https:\/\/test.com\/callback",
        "callback_error":0,
        "created_at":"2019-09-13 10:20:23"
    },
    {
        "id":11,
        "category":"btc",
        "address":"18Crf5jR5P9vryyjqPWJh1TZDTGXajcUgr",
        "callback":"https:\/\/test.com\/callback",
        "callback_error":0,
        "created_at":"2019-09-16 02:52:28"
    }
]
```

{% endtab %}
{% endtabs %}

### Response

Object [webhook](#webhook)

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

```php
$listWebHook = $webhookClient->list([
    "offset" => 0,
    "limit" => 10
]);
```

{% endtab %}
{% endtabs %}

## CreateHook

<mark style="color:green;">`POST`</mark> `https://api.blocksdk.com/v1/hook`

#### Headers

| Name      | Type   | Description            |
| --------- | ------ | ---------------------- |
| x-api-key | string | API authentication key |

#### Request Body

| Name     | Type   | Description                                    |
| -------- | ------ | ---------------------------------------------- |
| callback | string | Callback address to call when event occurs     |
| category | string | Cryptocurrency Types(btc,bch,ltc,dash,eth,xmr) |
| address  | string | Cryptocurrency Address                         |

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

```javascript
[]
```

{% endtab %}
{% endtabs %}

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

```php
$hook = $webhookClient->create([
    "callback" => "https://test.com/callback",
    "category" => "btc",
    "address" => "18Crf5jR5P9vryyjqPWJh1TZDTGXajcUgr"
]);
```

{% endtab %}
{% endtabs %}

## DeleteHook

<mark style="color:green;">`POST`</mark> `https://api.blocksdk.com/v1/hook/{hook_id}/delete`

#### Path Parameters

| Name     | Type   | Description         |
| -------- | ------ | ------------------- |
| hook\_id | string | aWeb Hook Unique ID |

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

```javascript
[]
```

{% endtab %}
{% endtabs %}

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

```php
$hook = $webhookClient->delete([
    "hook_id" => 1
]);
```

{% endtab %}
{% endtabs %}

## ListHookResponse

<mark style="color:blue;">`GET`</mark> `https://api.blocksdk.com/v1/hook/response`

#### Query Parameters

| Name   | Type   | Description                         |
| ------ | ------ | ----------------------------------- |
| offset | number | WebHookResponse List Offset         |
| limit  | number | Number of WebHookResponse to import |

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

```javascript
{
    "webhook_response":[
        {
            "webhook_id":1,
            "status":404,
            "event":"confirmed",
            "tx_hash":"892235a5aa0f52c2240603e9ca55012f0c76fee688623961003eae1f0ede4506",
            "datetime":"2019-12-15T18:42:15.000000Z"
        },
        {
            "webhook_id":1,
            "status":404,
            "event":"unconfirmed",
            "tx_hash":"892235a5aa0f52c2240603e9ca55012f0c76fee688623961003eae1f0ede4506",
            "datetime":"2019-12-15T02:38:00.000000Z"
       }
   ]
}
```

{% endtab %}
{% endtabs %}

### Response

Object [WebHookResponse](#webhookresponse)

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

```php
$listWebHook = $webhookClient->listResponse([
    "offset" => 0,
    "limit" => 10
]);
```

{% endtab %}
{% endtabs %}

## GetHook

<mark style="color:blue;">`GET`</mark> `https://api.blocksdk.com/v1/hook/{hook_id}`

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

```javascript
{
        "id":9,
        "category":"btc",
        "address":"17AJUKEaJPhrqSRwZtr3usw9Na6f8SHMqG",
        "callback":"https:\/\/test.com\/callback",
        "callback_error":0,
        "created_at":"2019-09-13 10:20:23"
}
```

{% endtab %}
{% endtabs %}

### Response

Object [WebHook](#webhook)

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

```php
$listWebHook = $webhookClient->get([
    "hook_id" => 9
]);
```

{% endtab %}
{% endtabs %}

## GetHookResponse

<mark style="color:blue;">`GET`</mark> `https://api.blocksdk.com/v1/hook/{hook_id}/response`

#### Query Parameters

| Name   | Type   | Description                         |
| ------ | ------ | ----------------------------------- |
| offset | number | WebHookResponse List Offset         |
| limit  | number | Number of WebHookResponse to import |

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

```javascript
{
    "webhook_response":[
        {
            "webhook_id":1,
            "status":404,
            "event":"confirmed",
            "tx_hash":"892235a5aa0f52c2240603e9ca55012f0c76fee688623961003eae1f0ede4506",
            "datetime":"2019-12-15T18:42:15.000000Z"
        },
        {
            "webhook_id":1,
            "status":404,
            "event":"unconfirmed",
            "tx_hash":"892235a5aa0f52c2240603e9ca55012f0c76fee688623961003eae1f0ede4506",
            "datetime":"2019-12-15T02:38:00.000000Z"
       }
   ]
}
```

{% endtab %}
{% endtabs %}

### Response

Object [WebHookResponse](#webhookresponse)

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

```php
$listWebHook = $webhookClient->getResponse([
    "hook_id" => 1,
    "offset" => 0,
    "limit" => 10
]);
```

{% endtab %}
{% endtabs %}
