Webhooks

Webhooks are used to send events from ReferralHero to your server. You can decide which events to send to your server.

To enable webhooks:

  • go to your campaign dashboard > Edit Campaign > Integrations > Webhooks

  • Click on the + New Webhook button

  • In the popup, add your endpoint URL and toggle the events you want to receive

  • Click on Create Webhook


Webhook Payload Verification

To ensure that your webhook payloads are authentic and have not been tampered with, ReferralHero includes a signature header in every webhook request. You can use this signature to validate requests.

⚠️ Important: Make sure to enable the “Payload Verification” toggle. Once enabled, a secret key will be generated. This key is required to decode and validate the signature header in your application that receives the webhook.


Where to Find Your Webhook Secret Key

You can find your Webhook Secret Key in two places:

Option 1: From Profile Menu

  1. Log in to your ReferralHero dashboard.

  2. Click on your profile button (top-right corner).

  3. In the popup, select Webhook Secret.

  4. You will see your Webhook Secret Key along with an option to regenerate it if needed.

Option 2: From Campaign Settings

  1. Log in to your ReferralHero dashboard.

  2. Click Edit Campaign for the campaign you want.

  3. Go to the Integration tab.

  4. Click on Webhook, and you will see the Webhook Secret Key.

Use this secret key in your server code to verify incoming webhooks.


Steps to Verify a Webhook

  1. Read the raw request body (e.g., request.raw_post in Rails).

  2. Retrieve the signature from the X-ReferralHero-Signature header.

  3. Recompute the HMAC-SHA256 hash of the raw body using your Webhook Secret Key as the secret.

  4. Compare your computed value with the signature header. If they match, the webhook is valid.


Code Examples

require 'openssl'
require 'base64'

class WebhooksController < ActionController::API
  skip_before_action :verify_authenticity_token

  def receive
    raw_payload = request.raw_post
    signature   = request.headers['X-ReferralHero-Signature']
    secret      = ENV['REFERRALHERO_API_KEY']

    computed_signature = Base64.strict_encode64(
      OpenSSL::HMAC.digest('sha256', secret, raw_payload)
    )

    unless ActiveSupport::SecurityUtils.secure_compare(signature.to_s, computed_signature)
      render json: { error: 'Invalid signature' }, status: :unauthorized and return
    end

    data = JSON.parse(raw_payload)
    # handle data...
    head :ok
  end
end

Backward Compatible: If you do not check this header, your existing webhooks will continue to work without any changes. 🔒 Recommended: Implement signature validation to ensure authenticity and security of incoming webhooks.

Events

ReferralHero sends a POST HTTP request with a JSON payload when specific events occur.

There are 6 types of events:

new_registration

Sent when a new person subscribes to your list. If you the confirmation email is disabled, the event is sent as soon as the person is subscribed to the list.

subscriber_promoted

Sent when a subscriber is promoted.

subscriber_updated

Sent when a subscriber field is updated.

subscriber_deleted

Sent when a subscriber is deleted.

reward_unlocked

Sent immediately when a subscriber qualifies for and unlocks a reward.

reward_sent

Sent when a reward is actually delivered to the subscriber. This happens only after conditions like 'Hold until manually reviewed' or 'Hold for X days' are fulfilled or Reward delivery set to 'Unlock and send reward immediately'.

Errors

Please send back a blank response with a status code of 200. All not-200 responses will be considered errors. After 10 consecutive bad responses, the webhook will be disabled.

If a webhook fails, we will try to deliver it 3 times over a period of 5 minutes.

How to test a webhook

To test a webhook just click on the Test button next to the webhook URL you want to test. We will ping your webhook URL with a JSON file containing fake data.

Last updated

Was this helpful?