Skip to content

๐Ÿ† Loyalty API โ€‹

๐Ÿ’ฐ Get Balance โ€‹

GET /api/loyalty/balance
Authorization: Bearer <customer-token>

Returns the customer's current loyalty point balance.

Response:

json
{
  "success": true,
  "data": {
    "points": 450,
    "transactions": [
      {
        "id": "cuid",
        "type": "EARN",
        "points": 50,
        "description": "Order #KA-20250615-001",
        "createdAt": "2025-06-15T12:00:00Z"
      }
    ]
  }
}

๐ŸŽ Redeem Points โ€‹

POST /api/loyalty/redeem
Authorization: Bearer <customer-token>

Request:

json
{
  "points": 100,
  "orderId": "order-id"
}

Response:

json
{
  "success": true,
  "data": {
    "remainingPoints": 350,
    "transaction": {
      "id": "cuid",
      "type": "REDEEM",
      "points": -100,
      "description": "Redeemed for order"
    }
  }
}

โš™๏ธ Adjust Points (Admin) โ€‹

POST /api/loyalty/customers/:id/adjust
Authorization: Bearer <manager-token>

Request:

json
{
  "points": 50,
  "description": "Compensation for delayed order"
}

Use negative values to deduct points.

Response:

json
{
  "success": true,
  "data": {
    "newBalance": 500,
    "transaction": {
      "id": "cuid",
      "type": "ADJUST",
      "points": 50,
      "description": "Compensation for delayed order"
    }
  }
}

๐Ÿ”’ Permissions Summary โ€‹

ActionRequired Role
๐Ÿ’ฐ Get balanceAuthenticated customer
๐ŸŽ Redeem pointsAuthenticated customer
โš™๏ธ Adjust pointsManager, Super Admin

โš ๏ธ Error Cases โ€‹

ScenarioStatusError
โŒ Insufficient points400Not enough loyalty points
๐Ÿ” Customer not found404Customer not found
โš ๏ธ Invalid points value400Points must be a positive number