Ecom API Reference

Base URL: /api. All request/response bodies are JSON.

Users (Unified auth)

DELETE /api/users/:id JWT
Deletes the user and related Seller/Buyer records. Only the same user or an admin can perform this.

Request

Responses

POST /api/users/resend-otp Public
Resends a new verification code (buyers or sellers).

Request body

{
  "email": "user@example.com"
}

Responses

POST /api/users/verify-email Public
Verifies the code, marks emailVerified, ensures a User exists, and returns JWT.

Request body

{
  "email": "user@example.com",
  "otp": "123456"
}

Responses

POST /api/users/login Public
Universal login for buyer, seller, and admin. Role is resolved from User.

Request body

{
  "username": "username-or-email",
  "password": "secret"
}

Responses

Products

GET /api/products Public
Lists all products. Supports filtering by category. Admins can see soft-deleted products as well.

Request

Examples

Responses

GET /api/products/:id Public
Get a specific product by ID.

Request

Responses

POST /api/products JWT (Seller/Admin)
Creates a new product. Only authenticated sellers or admins can create products.

Request

Responses

PATCH /api/products/:id JWT (Owner/Admin)
Partially updates an existing product. Only the product owner or admin can update it.

Request

Responses

DELETE /api/products/:id JWT (Owner/Admin)
Soft deletes a product. Only the product owner or admin can delete it. The product is not actually removed from the database but marked as deleted.

Request

Responses

Trial Policies

POST /api/products/:id/trial-policy JWT (Seller/Admin)
Creates a trial policy for a product. Only authenticated sellers or admins can create trial policies.

Request

Responses

PATCH /api/products/:id/trial-policy JWT (Seller/Admin)
Updates an existing trial policy. Only the product owner or admin can update it. All fields are optional.

Request

Responses

DELETE /api/products/:id/trial-policy JWT (Seller/Admin)
Soft deletes/disables a trial policy. Only the product owner or admin can delete it.

Request

Responses

GET /api/products/:id/trial-policy Public
Gets the trial policy for a specific product.

Request

Responses

Buyers

POST /api/buyers/register Public
Registers a buyer with a profile picture and sends OTP.

Request

firstName: "John"
lastName: "Doe"
username: "johnd"
email: "john@example.com"
phoneNumber: "+1000000000"
password: "secret"
profilePic: <file> // required image file field

Responses

GET /api/buyers JWT
List buyers.
GET /api/buyers/:id JWT
Get buyer by id.
PATCH /api/buyers/:id JWT (self/admin)
Update buyer fields.
DELETE /api/buyers/:id JWT (self/admin)
Delete buyer.

Sellers

POST /api/sellers/register Public
Registers a seller with license and profile picture uploads, then sends OTP. Login requires emailVerified=true and approved=true.

Request

firstName: "Acme"
lastName: "Corp"
username: "acme"
email: "acme@example.com"
password: "secret"
address: "123 Main St"
phoneNumber: "+1000000000"   // optional
storeName: "Acme Store"      // optional
license: <file>             // required image file field
profilePic: <file>          // required image file field

Responses

GET /api/sellers JWT (admin)
Get all sellers. Admin only.

Request

Responses

GET /api/sellers/:id JWT
Get seller by ID. Authenticated users only.

Request

Responses

PUT /api/sellers/:id JWT
Update seller information. Authenticated users only.

Request

Request body (all fields optional)

{
  "firstName": "Updated Name",
  "lastName": "Updated Last",
  "email": "updated@example.com",
  "address": "Updated Address",
  "license": "NEW-LIC-123",
  "approved": true
}

Responses

  • 200: { "message": "Seller updated successfully", "seller": { id, firstName, lastName, phoneNumber, storeName, username, email, address, license, approved, emailVerified, profilePic } }
  • 401: { "message": "Unauthorized" }
  • 404: { "message": "Seller not found" }
  • 500: { "message": "Error updating seller", "error": "..." }
  • Orders

    POST /api/orders JWT
    Creates a new order. Only authenticated buyers can create orders.

    Request

    Responses

    GET /api/orders Public
    Lists all orders with optional filtering and pagination.

    Request

    Responses

    GET /api/orders/:id JWT
    Get a specific order by ID with product and buyer details.

    Request

    Responses

    GET /api/orders/buyer/:buyerId JWT
    Get all orders for a specific buyer with pagination. Uses authenticated buyer's username to find correct buyer ID.

    Request

    Responses

    GET /api/orders/seller/:sellerId JWT
    Get all orders for products belonging to a specific seller. Uses INNER JOIN to filter orders by product ownership.

    Request

    Responses

    Returns

    POST /api/returns JWT (Buyer)
    Initiate a return for an order. Only allowed during active trial period. Creates return record with QR token and updates order status.

    Request

    Responses

    POST /api/returns/scan JWT (Seller)
    Seller scans QR code to accept return or claim defect. Supports file upload for defect photos.

    Request

    Responses

    GET /api/returns/order/:orderId JWT
    Get return details for a specific order. Only accessible by the order buyer or admins.

    Request

    Responses

    GET /api/returns/seller/:sellerId JWT
    Get all returns for products belonging to a specific seller with pagination and filtering.

    Request

    Responses

    GET /api/returns/buyer/:buyerId JWT
    Get all returns for a specific buyer with pagination and filtering.

    Request

    Responses

    Admin

    PATCH /api/admin/sellers/:id/approve JWT (Admin)
    Approve a seller account. Only admins can approve sellers.

    Request

    Responses

    Rental Products

    GET /api/rentals Public
    Lists all available rental products with pagination.

    Request

    Responses

    GET /api/rentals/:id Public
    Get a specific rental product by ID.

    Request

    Responses

    POST /api/rentals JWT (Seller/Admin)
    Creates a new product and rental listing in a single transaction. Supports image uploads.

    Request

    name: "string (required)"
    description: "string (required)"
    category: "string (required)"
    condition: "string (optional, enum: ['new', 'used', 'refurbished'], default: 'new')"
    price: "number (required, > 0)"
    dailyRate: "number (required, > 0)"
    penaltyRate: "number (optional, default: 0.00)"
    images: "file[] (optional, up to 10 images)"
    ownerId: "UUID (optional, admin only - for assigning to specific seller)"

    Responses

    PATCH /api/rentals/:id JWT (Owner/Admin)
    Updates both product and rental details. Only the product owner or admin can update.

    Request

    {
      "name": "string",
      "description": "string",
      "category": "string",
      "condition": "string (enum: ['new', 'used', 'refurbished'])",
      "price": "number (> 0)",
      "dailyRate": "number (> 0)",
      "penaltyRate": "number",
      "available": "boolean"
    }

    Responses

    DELETE /api/rentals/:id JWT (Owner/Admin)
    Deletes a rental product. Only the product owner or admin can delete.

    Request

    Responses

    GET /api/rentals/renter/:renterId JWT
    Get all rental products listed by a specific seller (renter). Users can only view their own listings unless admin.

    Request

    Responses

    Payments

    POST /api/payments/initiate JWT
    Initiates payment with Chapa for a specific order. Creates payment record and returns checkout URL.

    Request

    Responses

    POST /api/payments/verify Public
    Chapa webhook endpoint for payment verification. Processes payment callbacks and updates payment/order status. Redirects to success/failure pages.

    Request

    Responses

    This is a webhook endpoint called by Chapa. Also handles browser redirects from payment completion.
    GET /api/payments/verifyy Public
    Browser redirect endpoint after payment completion. Simply redirects to success page.

    Request

    Responses

    This endpoint handles the browser redirect from Chapa checkout. The 'y' in 'verifyy' distinguishes it from the webhook endpoint.
    GET /api/payments/status Public
    Checks the current status of a payment using transaction reference.

    Request

    Responses

    Security