# Webhooks

Webhooks are used to send events from SparkLoop to your server. We send a `POST HTTP` request with a JSON payload when specific events occur.

## Create a webhook

To create a webhook:

* go to your [*Account Settings > Integrations*](https://dash.sparkloop.app/settings/integrations)
* enter the URL of your webhook and choose which events you want to receive

<figure><img src="https://307340109-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LvjCB8kc4yvMRscfT0m%2Fuploads%2FJGbn5JEDnDI6osBst4Zm%2Fimage.png?alt=media&#x26;token=9cac738b-4945-499f-896a-597e9ba30f88" alt=""><figcaption></figcaption></figure>

## Update/delete a webhook

To update or delete a webhook hover over the three dots to the right of the webhook to open the settings menu and click on the link to update or delete.

<figure><img src="https://307340109-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LvjCB8kc4yvMRscfT0m%2Fuploads%2F6KQi5p6foitetARyDgPI%2Fimage.png?alt=media&#x26;token=05ff05c8-088b-4f35-af64-363de029524f" alt=""><figcaption></figcaption></figure>

## Test a webhook

To test a webhook hover over the three dots to the right of the webhook to open the settings menu and click on "Send test webhook"

![](https://307340109-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LvjCB8kc4yvMRscfT0m%2Fuploads%2FhoH0v7BKT7IWilrJaSTm%2Fimage.png?alt=media\&token=dfbe0caf-7a61-48ff-ad6c-1a338512de7d)

## Authentication token

SparkLoop authenticates all webhooks with a token in the `SparkLoop-Token` request header. This allows you to verify that the events were sent by SparkLoop, not by a third party.

While this is entirely optional, it adds an extra layer of security: simply check the token in the `SparkLoop-Token` header is the same as your authentication token. If not, ignore the webhook!

You can find your authentication token in [your Webhooks page](https://dash.sparkloop.app/settings/integrations).

## Events

### **new\_referral**

Is sent when a new referral made by a subscriber in a referral program is tracked

```json
{
  "type": "new_referral",
  "campaign_id": "MF6319db9890",
  "subscriber": {
    "id": "sub_hjdgc74u",
    "first_name": "John",
    "name": "John Doe",
    "email": "john.doe@email.com",
    "referral_code": "ada90f39",
    "referral_link": "https://mywebsite.com?rh_ref=ada90f39",
    "referred": true,
    "tot_referrals": 0,
    "next_reward": 2,
    "created_at": 1564400550
  },
  "referrer": {
    "id": "sub_93ehus8h",
    "first_name": "John",
    "name": "John Smith",
    "email": "john.smith@email.com",
    "referral_code": "f9464199",
    "referral_link": "https://mywebsite.com?rh_ref=f9464199",
    "referred": false,
    "tot_referrals": 4,
    "next_reward": 1,
    "created_at": 1564403873
  }
}
```

### **new\_partner\_pending\_referral**

Is sent when a referral made by a partner is starts the screening period

```json
{
  "type": "new_partner_pending_referral",
  "campaign": {
    "id": "partner_campaign_de9c1c7c7bbc",
    "referral_code": "1b5b5c4094",
    "type": "partner_program",
    "upscribe": true,
    "partner_program_id": "partner_program_5b925f623c28"
    "publication_id": "pub_a6db3f666c55",
    "created_at": 1658780774
  },
  "subscriber": {
    "id": "sub_042448acb02a",
    "first_name": null,
    "name": null,
    "email": "test12345@test.com",
    "referral_code": "6363a0b5",
    "referred": true,
    "tot_referrals": 0,
    "referral_status": "pending",
    "last_reward": null,
    "partner_id": "partner_0a8a45c403f8",
    "created_at": 1659536359
  },
  "partner": {
    "id": "partner_0a8a45c403f8",
    "name": "Jason Resnickss",
    "logo": "http://dash.sparkloop.app/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBPQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--36ac8d234a450db1db32c62fe9e399b29a9e42f0/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2RwQVpacEFaWT0iLCJleHAiOm51bGwsInB1ciI6InZhcmlhdGlvbiJ9fQ==--b97dd663f95aeeb4752185ef091f0728b0f28f4a/active_campaign.png"
  }
}
```

### **new\_partner\_referral**

Is sent when a referral made by a partner is confirmed

```json
{
  "type": "new_partner_referral",
  "campaign": {
    "id": "partner_campaign_de9c1c7c7bbc",
    "referral_code": "1b5b5c4094",
    "type": "partner_program",
    "upscribe": true,
    "partner_program_id": "partner_program_5b925f623c28"
    "publication_id": "pub_a6db3f666c55",
    "created_at": 1658780774
  },
  "subscriber": {
    "id": "sub_042448acb02a",
    "first_name": null,
    "name": null,
    "email": "test12345@test.com",
    "referral_code": "6363a0b5",
    "referred": true,
    "tot_referrals": 0,
    "referral_status": "verified",
    "last_reward": null,
    "partner_id": "partner_0a8a45c403f8",
    "created_at": 1659536359
  },
  "partner": {
    "id": "partner_0a8a45c403f8",
    "name": "Jason Resnickss",
    "logo": "http://dash.sparkloop.app/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBPQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--36ac8d234a450db1db32c62fe9e399b29a9e42f0/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2RwQVpacEFaWT0iLCJleHAiOm51bGwsInB1ciI6InZhcmlhdGlvbiJ9fQ==--b97dd663f95aeeb4752185ef091f0728b0f28f4a/active_campaign.png"
  }
}
```

### **new\_offer\_lead**

Is sent when a new lead is confirmed

```json
{
  "type": "new_offer_lead",
  "offer_id": "offer_de9c1c7c7bbc",
  "lead": {
    "id": "offer_conversion_an324nf332f",
    "email": "test12345@test.com",
    "source": "sparkloop-upscribe",
    "partner_id": "partner_0a8a45c403f8",
    "referral_status": "confirmed",
    "offer_recommendation_id": "offer_recommendation_dsfhgfb476f,
    "created_at": 1659536359,
    "referred_at": 1659536359
  },
  "partner": {
    "id": "partner_0a8a45c403f8",
    "name": "Jason Resnickss",
    "logo": "http://dash.sparkloop.app/rails/active_storage/representations/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBPQT09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX2lkIn19--36ac8d234a450db1db32c62fe9e399b29a9e42f0/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaDdCam9VY21WemFYcGxYM1J2WDJ4cGJXbDBXd2RwQVpacEFaWT0iLCJleHAiOm51bGwsInB1ciI6InZhcmlhdGlvbiJ9fQ==--b97dd663f95aeeb4752185ef091f0728b0f28f4a/active_campaign.png"
  }
}
```

### **reward\_unlocked** <a href="#reward_unlocked" id="reward_unlocked"></a>

Is sent when a subscriber hits a milestone and unlocks a reward&#x20;

```json
{
  "type": "reward_unlocked",
  "campaign_id": "MF6319db9890",
  "referrals": 4,
  "coupon_code": "9wusha0",
  "subscriber": {
    "id": "sub_hjdgc74u",
    "first_name": "John",
    "name": "John Doe ",
    "email": "john.doe@email.com",
    "referral_code": "f9464199",
    "referral_link": "https://mywebsite.com?rh_ref=f9464199",
    "referred": true,
    "tot_referrals": 4,
    "next_reward": 2,
    "created_at": 1564403873
  },
  "reward": {
    "id": "reward_cdebf4f013",
    "name": "2018 Private Report: State of the Ecommerce",
    "referrals": 4,
    "recurring": false
  }
}
```

### **reward\_redeemed** <a href="#reward_unlocked" id="reward_unlocked"></a>

Is sent when a subscriber redeems a reward by submitting their address details.

```json
{
  "type": "reward_redeemed",
  "campaign_id": "MF6319db9890",
  "referrals": 4,
  "coupon_code": "9wusha0",
  "subscriber": {
    "id": "sub_hjdgc74u",
    "first_name": "John",
    "name": "John Doe ",
    "email": "john.doe@email.com",
    "referral_code": "f9464199",
    "referral_link": "https://mywebsite.com?rh_ref=f9464199",
    "referred": true,
    "tot_referrals": 4,
    "next_reward": 2,
    "created_at": 1564403873
  },
  "reward": {
    "id": "reward_cdebf4f013",
    "name": "2018 Private Report: State of the Ecommerce",
    "referrals": 4,
    "recurring": false
  },
  "reward_variant_name": "T-Shirt XXL",
  "reward_variant_sku": "t_shirt_xxl",
  "shipping_details": {
    "shipping_name": "John Doe",
    "shipping_phone": "+01 407-889-2040",
    "shipping_address_1": "7838 Pearl Drive",
    "shipping_address_2": null,
    "shipping_city": "Sun City",
    "shipping_state_code": "AZ",
    "shipping_zipcode": "85351",
    "shipping_country_code": "US"
  }
}
```

### **sync\_subscriber** <a href="#sync_subscriber" id="sync_subscriber"></a>

Is sent when a referral is created or updated.

```json
{
  "type": "sync_subscriber",
  "subscriber": {
    "id": "sub_hjdgc74u",
    "first_name": "John",
    "name": "John Doe ",
    "email": "john.doe@email.com",
    "referral_code": "f9464199",
    "referral_link": "https://mywebsite.com?rh_ref=f9464199",
    "referred": true,
    "tot_referrals": 4,
    "referral_status": "rejected",
    "next_reward": 2,
    "created_at": 1564403873
  }
}
```

## Errors

Please send back a blank response with a status code of `200`.\
All not-200 responses will be considered errors.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sparkloop.app/webhooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
