# Webhooks

## Create new webhook

<mark style="color:green;">`POST`</mark> `https://api.sparkloop.app/v2/webhooks`

#### Request Body

| Name                                  | Type    | Description                                                                         |
| ------------------------------------- | ------- | ----------------------------------------------------------------------------------- |
| url<mark style="color:red;">\*</mark> | String  | Webhook's URL                                                                       |
| new\_referral                         | boolean | If you want to receive webhook notifications for new referrals in referral programs |
| reward\_unlocked                      | boolean | If you want to receive webhook notifications when rewards are unlocked              |
| new\_partner\_referral                | String  | If you want to receive webhook notifications for new referrals from partners        |
| reward\_redeemed                      | String  | If you want to receive webhook notifications when rewards are redeemed              |

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

```javascript
{
    "webhook": {
        "uuid": "webhook_ac06a45cb5",
        "url": "https://webhook.site/6819636c-fd8d-45bd-a1bf-e154cd9f2d68",
        "events": {
            "new_referral": true,
            "reward_unlocked": false
        }
    }
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    "error": "Url must start with https://"
}
```

{% endtab %}
{% endtabs %}

## Get webhooks

<mark style="color:blue;">`GET`</mark> `https://api.sparkloop.app/v2/webhooks`

Webhooks are returned in descending order of creation.

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

```javascript
{
    "webhooks": [
        {
            "uuid": "webhook_6f06b5421a",
            "url": "https://webhook.site/9a470b66-2d72-413e-b42d-c59c61cd4be6",
            "events": {
                "new_referral": false,
                "reward_unlocked": true
            }
        },
        {
            "uuid": "webhook_e4a23cc058",
            "url": "https://webhook.site/9a470b66-2d72-413e-b42d-c59c61cd4be6",
            "events": {
                "new_referral": true,
                "reward_unlocked": false
            }
        }
    ]
}
```

{% endtab %}

{% tab title="404: Not Found " %}

```javascript
{
    "error": "Campaign MF9a7d8983d1c not found!"
}
```

{% endtab %}
{% endtabs %}

## Get a webhook by UUID

<mark style="color:blue;">`GET`</mark> `https://api.sparkloop.app/v2/webhooks/:identifier`

#### Path Parameters

| Name                                         | Type   | Description    |
| -------------------------------------------- | ------ | -------------- |
| identifier<mark style="color:red;">\*</mark> | String | Webhook's UUID |

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

```javascript
{
    "webhook": {
        "uuid": "webhook_ac06a45cb5",
        "url": "https://webhook.site/6819636c-fd8d-45bd-a1bf-e154cd9f2d68",
        "events": {
            "new_referral": true,
            "new_partner_referral": null,
            "reward_unlocked": null,
            "reward_redeemed": true
        }
    }
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    "error": "Webhook uuid blank!"
}
```

{% endtab %}

{% tab title="404: Not Found " %}

```javascript
{
    "error": "Webhook webhook_ABC not found!"
}
```

{% endtab %}
{% endtabs %}

## Update a webhook

<mark style="color:orange;">`PUT`</mark> `https://api.sparkloop.app/v2/webhooks/:identifier`

#### Path Parameters

| Name                                         | Type   | Description    |
| -------------------------------------------- | ------ | -------------- |
| identifier<mark style="color:red;">\*</mark> | String | Webhook's UUID |

#### Request Body

| Name                   | Type    | Description                                                                  |
| ---------------------- | ------- | ---------------------------------------------------------------------------- |
| url                    | String  | Webhook's URL                                                                |
| new\_referral          | boolean | If you want to receive webhook notifications for new referrals               |
| reward\_unlocked       | boolean | If you want to receive webhook notifications when rewards are unlocked       |
| new\_partner\_referral | String  | If you want to receive webhook notifications for new referrals from partners |
| reward\_redeemed       | String  | If you want to receive webhook notifications when rewards are redeemed       |

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

```javascript
{
    "webhook": {
        "uuid": "webhook_ac06a45cb5",
        "url": "https://webhook.site/6819636c-fd8d-45bd-a1bf-e154cd9f2d68",
        "events": {
            "new_referral": true,
            "new_partner_referral": null,
            "reward_unlocked": null,
            "reward_redeemed": true
        }
    }
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    "error": "Url must start with https://"
}
```

{% endtab %}
{% endtabs %}

## Delete a webhook

<mark style="color:red;">`DELETE`</mark> `https://api.sparkloop.app/v2/webhooks/:identifier`

#### Path Parameters

| Name                                         | Type   | Description    |
| -------------------------------------------- | ------ | -------------- |
| identifier<mark style="color:red;">\*</mark> | String | Webhook's UUID |

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

```javascript
{
    "message": "Successfully deleted webhook webhook_abc"
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    "error": "Webhook uuid blank!"
}
```

{% endtab %}

{% tab title="404: Not Found " %}

```javascript
{
    "error": "Webhook webhook_ABC not found!"
}
```

{% endtab %}
{% endtabs %}
