Node.js

Use our node package to simplify the integration

Installation

To get started with Refir, you can install it using npm or yarn:

npm install refir
# or
yarn add refir

Configuration

Before using Refir, you need to configure it with your API key. You can do this as follows:

const Refir = require("refir");

const refir = new Refir();
refir.configure({ apiKey: "your-api-key" });

Usage

Adding a User

You can use Refir to add a user to your referral program. The following example demonstrates how to do this:

const user = {
  userId: "unique-user-id",
  name: "John Doe",
  email: "johndoe@example.com",
};

const user = await refir.addUser(user);

if (user.status) {
  console.log(user);
  console.log("User added successfully.");
} else {
  console.error("Failed to add user.");
}

Getting a User by ID

You can retrieve a user's referral code by their unique ID using Refir. Here's an example of how to do it:

const userId = "unique-user-id";

const referral = await refir.getUserById(userId);

if (referral.status) {
  console.log(`User's referral code and link: ${referralCode.data}`);
} else {
  console.error("Failed to get user referral code.");
}

Error handling

Refir provides basic error handling for API requests. If an error occurs during an API request, an error message will be logged to the console, and the function will return false. You can customize error handling to suit your application's needs.

Last updated