useLoyalty
Server SDK

Server SDK Overview

Build powerful gamification features with the useLoyalty Server SDK

The useLoyalty Server SDK provides a typed client and RESTful API for integrating gamification features into your application. Use it to manage members, award points, track quests, and create engaging loyalty experiences.

Installation

npm install @useloyalty/sdk
# or
pnpm add @useloyalty/sdk

Quick Start

import { UseLoyaltyClient } from "@useloyalty/sdk";

const useLoyalty = new UseLoyaltyClient({
  publicKey: process.env.USELOYALTY_PUBLIC_KEY!,
  privateKey: process.env.USELOYALTY_PRIVATE_KEY!,
});

// Award points
await useLoyalty.members.awardPoints("user_123", {
  amount: 100,
  description: "Welcome bonus",
});

// Track events
await useLoyalty.events.track("user_123", {
  event: "purchase",
  properties: { amount: 99.99 },
});

// Generate widget auth
const auth = useLoyalty.generateWidgetAuth("user_123");

Using Raw REST API

const response = await fetch(
  "https://app.useloyalty.app/api/v1/members/user_123/points",
  {
    method: "POST",
    headers: {
      Authorization: "Bearer sk_your_private_key",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      amount: 100,
      description: "Welcome bonus",
    }),
  },
);

Base URL

https://app.useloyalty.app/api/v1

Key Features

API Endpoints Summary

ResourceEndpoints
MembersPOST /members, GET /members, GET /members/:id, PATCH /members/:id, DELETE /members/:id
PointsGET /members/:id/points, POST /members/:id/points
BadgesGET /members/:id/badges, POST /members/:id/badges, DELETE /members/:id/badges
QuestsPOST /quests/:id/complete, POST /quests/:id/progress
EventsPOST /events
ReferralsPOST /referrals/apply, POST /referrals/convert, GET /referrals/stats/:id
Promo CodesPOST /promo-codes/redeem

Response Format

All API responses follow a consistent JSON format:

{
  "success": true,
  "data": { ... }
}

Error responses include a message:

{
  "error": "Invalid API key",
  "message": "The provided API key is not valid"
}

HTTP Status Codes

CodeDescription
200Success
201Created
400Bad request / Validation error
401Unauthorized / Invalid API key
404Resource not found
409Conflict (e.g., duplicate resource)
500Server error

Rate Limiting

API requests are rate limited per API key. Current limits:

  • 1000 requests/minute for standard operations
  • 100 requests/minute for bulk operations

Rate limit headers are included in responses:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 999
X-RateLimit-Reset: 1640000000

Next Steps

  1. Get your API keys
  2. Create your first member
  3. Award points

On this page