# Webhooks

## Create new webhook

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

#### Path Parameters

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

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-Api-Key<mark style="color:red;">\*</mark> | String | API Key     |

#### 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         |
| reward\_unlocked                      | boolean | If you want to receive webhook notifications when rewards are unlocked |

{% 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": null
        }
    }
}
```

{% 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/v1/campaigns/:campaign_uuid/webhooks`

Webhooks are returned in descending order of creation.

#### Path Parameters

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

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-Api-Key<mark style="color:red;">\*</mark> | String | Api Key     |

{% 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/v1/campaigns/:campaign_uuid/webhooks/:uuid`

#### Path Parameters

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

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-Api-Key<mark style="color:red;">\*</mark> | String | API Key     |

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

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

{% 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/v1/campaigns/:campaign_uuid/webhooks/:uuid`

#### Path Parameters

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

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-Api-Key<mark style="color:red;">\*</mark> | String | API Key     |

#### 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 |

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

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

{% 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/v1/campaigns/:campaign_uuid/webhooks/:uuid`

#### Path Parameters

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

#### Headers

| Name                                        | Type   | Description |
| ------------------------------------------- | ------ | ----------- |
| X-Api-Key<mark style="color:red;">\*</mark> | String | API Key     |

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