Skip to main content

Overview

The Admin API provides privileged endpoints for platform administrators to manage seller verifications, validate veterinary records, monitor platform statistics, and moderate content.
All admin endpoints require both authentication and admin role authorization. Requests without valid admin credentials will be rejected with a 403 Forbidden response.

Authentication & Authorization

Admin endpoints use two-layer protection:
  1. Authentication: Valid JWT token in Authorization: Bearer <token> header
  2. Authorization: User must have role: "admin" in their account

Access Control

Admin routes are protected by two middleware functions (server/src/routes/admin.ts:11):
  • authenticate - Validates JWT token and loads user context
  • requireAdmin - Verifies user has admin role
Unauthorized requests receive:

Get Admin Dashboard

Retrieves platform-wide statistics for the admin dashboard. Endpoint: GET /api/admin/dashboard

Response

boolean
required
Indicates request success
object
required
number
Total registered users across all roles
number
Number of sellers awaiting verification
number
Total horses listed on the platform
number
Number of horses with status “active”
number
Veterinary records awaiting validation

Example Response


Get Pending Sellers

Retrieves all sellers with pending verification status for admin review. Endpoint: GET /api/admin/sellers/pending

Response

boolean
required
Indicates request success
array
required
Array of seller objects awaiting verification
string
Seller’s email address
string
Seller’s full name
string
Seller’s phone number
object
string
Current status (will be “pending”)
string
Business name if applicable
number
Years of horse trading experience
string
Account creation timestamp

Example Response


Verify Seller

Approve or reject a seller’s verification request. Endpoint: PUT /api/admin/sellers/:id/verify

Path Parameters

string
required
Seller’s user ID (MongoDB ObjectId)

Body Parameters

string
required
Action to perform: "approve" or "reject"
string
Required when action is “reject”. Reason for rejection shown to seller

Response

boolean
required
Indicates request success
string
required
Human-readable result message
object
required
Updated seller user object (password excluded)
object
string
Updated status: “verified” or “rejected”
boolean
True if approved, false if rejected
string
Set to “manual” when approved by admin
string
Timestamp of verification (approve only)
string
Admin user ID who performed verification
string
Reason for rejection (reject only)

Example Response (Approved)

Example Response (Rejected)

Error Responses

Invalid seller ID or action parameter
Seller not found

Get Pending Vet Records

Retrieves all veterinary records awaiting validation, sorted by creation date (oldest first). Endpoint: GET /api/admin/vet-records/pending

Response

boolean
required
Indicates request success
array
required
Array of pending vet records with populated horse information
string
Vet record ID
object
Populated horse object
string
Horse ID
string
Horse name
string
Horse breed
string
Owner/seller ID
string
Type of record (e.g., “vaccination”, “health_check”)
string
URL to uploaded veterinary document
string
Current status (will be “pending”)
string
Record creation timestamp

Example Response


Validate Vet Record

Validate or reject a veterinary record submission. Endpoint: PUT /api/admin/vet-records/:id/validate

Path Parameters

string
required
Vet record ID (MongoDB ObjectId)

Body Parameters

string
required
Action to perform: "validate" or "reject"
string
Required when action is “reject”. Reason for rejection

Response

boolean
required
Indicates request success
object
required
Updated vet record object
string
Updated status: “validated” or “rejected”
string
Admin user ID who performed validation (validate only)
string
Timestamp of validation (validate only)
string
Reason for rejection (reject only)

Example Response (Validated)

Example Response (Rejected)

Error Responses

Invalid action parameter
Vet record not found

Delete Horse Listing

Permanently delete a horse listing and all associated veterinary records. This is a destructive operation that cannot be undone. Endpoint: DELETE /api/admin/horses/:id
This performs a hard delete, removing the horse listing and all related vet records from the database permanently. Use with caution.

Path Parameters

string
required
Horse listing ID (MongoDB ObjectId)

Response

boolean
required
Indicates request success
string
required
Confirmation message

Example Response

Use Cases

  • Remove fraudulent or inappropriate listings
  • Delete duplicate entries
  • Remove horses that violate platform policies
  • Clean up test data

Error Handling

All admin endpoints follow consistent error response patterns:

401 Unauthorized

Missing or invalid authentication token:

403 Forbidden

Valid user but not an admin:

500 Server Error

Internal server error:

Security Best Practices

Admin Token Security

  • Store admin tokens securely (never in client-side code)
  • Use environment variables for token storage
  • Implement token rotation policies
  • Log all admin actions for audit trails

Action Verification

  • Verify seller/record details before approval/rejection
  • Provide clear rejection reasons for transparency
  • Review documents thoroughly before validation
  • Confirm destructive operations (deletes) before execution

Access Monitoring

  • Monitor admin API usage patterns
  • Set up alerts for unusual activity
  • Regular audit of admin account access
  • Implement rate limiting for admin endpoints

User Management

View and manage user accounts

Horse Listings

Browse and manage horse listings

Vet Records

Public vet record endpoints

Authentication

User and admin authentication