Webhook

Receive real-time notifications when referrals occur

Implementing Referral Webhooks

Referral Webhooks provide a way for campaign owners to receive real-time notifications when new users are added to their referral program or when referrals occur. To integrate the Referral Webhook into your project, follow these steps:

Receive Webhook Notifications

Refir will send a POST request to the specified webhook URL when certain events occur, such as a new user being added or a successful referral. Your server should be prepared to receive these notifications.

Set Up an Endpoint to Receive Webhooks

Create an endpoint or route in your server application to handle incoming Referral Webhook notifications. The endpoint should listen for POST requests and be configured to handle JSON payloads.

Here's an example using Express.js:

const express = require('express');
const bodyParser = require('body-parser');
const app = express();

// Configure Express to parse JSON payloads
app.use(bodyParser.json());

// Define a route to handle Referral Webhook notifications
app.post('/webhook', (req, res) => {
  const data = req.body;

  // Process the data from the webhook
  // Implement your logic here to handle the referral notification
  // For example, reward user, update your database, send notifications, etc.

  // Respond to the webhook request
  res.status(200).json({ message: 'Webhook received successfully' });
});

// Start the server
const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});

Process Webhook Data

Inside the route handler for your webhook endpoint, you can access the data sent by Refir in the req.body object. The data typically includes information about the new lead, referring user, and a message.

You should implement your custom logic to process this data according to your application's requirements. For example, you can reward the user, update your database to reflect the referral, send email notifications, or trigger other actions.

Respond to the Webhook Request

After processing the webhook data, always respond with an HTTP status code of 200 to acknowledge receipt of the webhook. This ensures that Refir knows the webhook was successfully received.

Configure Your Webhook URL

In your Refir dashboard or settings, you will have the option to specify the webhook URL where Refir should send notifications. Enter the URL of your webhook endpoint (e.g., https://yourwebsite.com/webhook) in the provided field.

Test the Integration

To ensure that your webhook is working correctly, you can perform tests by adding users to your referral program and checking if your webhook endpoint receives and processes the notifications as expected.

Last updated