Sell Daily API

v1.0.0 | RESTful E-commerce Platform

View on GitHub

Base URL: http://127.0.0.1:5000

Overview

Welcome to the Sell Daily API documentation. This RESTful API provides a complete e-commerce solution with separate interfaces for administrators and customers. The API supports product management, order processing, user authentication, and administrative functions.

Note: This API is currently in development and running on localhost. Replace the base URL with your production domain when deploying.

Authentication

The Sell Daily API uses token-based authentication. Protected endpoints require a valid JWT token in the Authorization header.

Header Format:

Authorization: Bearer YOUR_JWT_TOKEN

Admin endpoints require admin authentication

User endpoints require user authentication

Error Handling

The API uses standard HTTP status codes and returns errors in JSON format.

Status Code Description
200Success
201Created
400Bad Request
401Unauthorized
403Forbidden
404Not Found
500Internal Server Error

Error Response Format:

{
  "error": "Error message description",
  "status": 400
}

Admin Endpoints

Administrative functions for managing products, orders, and users.

Admin Signup

GET

Create a new administrator account. This endpoint is for testing purposes only and should be replaced with a POST method in production.

Endpoint:

GET /admin/signup

Query Parameters:

Parameter Type Required Description
usernamestringYesAdmin username
emailstringYesAdmin email address
passwordstringYesAdmin password

Example Request:

GET http://127.0.0.1:5000/admin/signup?username=admin&email=admin@selldaily.com&password=securepass123

Success Response (201):

{
  "message": "Admin account created successfully",
  "admin": {
    "id": 1,
    "username": "admin",
    "email": "admin@selldaily.com",
    "created_at": "2025-10-10T14:30:00Z"
  }
}

Error Response (400):

{
  "error": "Admin with this email already exists",
  "status": 400
}

Admin Login

POST

Authenticate an administrator and receive a JWT token for accessing protected admin endpoints.

POST /admin/login

Request Body:

{
  "email": "admin@selldaily.com",
  "password": "securepass123"
}

Success Response (200):

{
  "message": "Login successful",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "admin": {
    "id": 1,
    "username": "admin",
    "email": "admin@selldaily.com"
  }
}

Error Response (401):

{
  "error": "Invalid credentials",
  "status": 401
}

Add Product

POST

Add a new product to the inventory. Requires admin authentication.

POST /add-product

Authentication Required: Include admin JWT token in Authorization header

Request Body (multipart/form-data):

Field Type Required Description
namestringYesProduct name
descriptionstringYesProduct description
pricenumberYesProduct price
categorystringYesProduct category
stockintegerYesAvailable quantity
imagefileNoProduct image

Success Response (201):

{
  "message": "Product added successfully",
  "product": {
    "id": 15,
    "name": "Premium Rice 5kg",
    "description": "High quality long grain rice",
    "price": 4500.00,
    "category": "Food & Beverages",
    "stock": 100,
    "image_url": "/uploads/rice_5kg.jpg",
    "created_at": "2025-10-10T14:35:00Z"
  }
}

View Products

GET

Retrieve all products in the system with detailed information. Admin view includes stock levels and sales data.

GET /view-product

Success Response (200):

{
  "products": [
    {
      "id": 1,
      "name": "Premium Rice 5kg",
      "description": "High quality long grain rice",
      "price": 4500.00,
      "category": "Food & Beverages",
      "stock": 100,
      "image_url": "/uploads/rice_5kg.jpg",
      "total_sold": 45,
      "created_at": "2025-10-01T10:00:00Z",
      "updated_at": "2025-10-10T14:35:00Z"
    },
    {
      "id": 2,
      "name": "Cooking Oil 2L",
      "description": "Pure vegetable cooking oil",
      "price": 2800.00,
      "category": "Food & Beverages",
      "stock": 75,
      "image_url": "/uploads/oil_2l.jpg",
      "total_sold": 32,
      "created_at": "2025-10-01T10:15:00Z",
      "updated_at": "2025-10-08T09:20:00Z"
    }
  ],
  "total_products": 2
}

Update Product

PUT

Update details of a specific product by its ID. All fields are optional; only provided fields will be updated.

PUT /update-product/:id

Authentication Required: Admin JWT token

URL Parameters:

idProduct ID to update

Request Body Example:

{
  "name": "Premium Basmati Rice 5kg",
  "price": 5200.00,
  "stock": 120
}

Success Response (200):

{
  "message": "Product updated successfully",
  "product": {
    "id": 1,
    "name": "Premium Basmati Rice 5kg",
    "description": "High quality long grain rice",
    "price": 5200.00,
    "category": "Food & Beverages",
    "stock": 120,
    "image_url": "/uploads/rice_5kg.jpg",
    "updated_at": "2025-10-10T15:00:00Z"
  }
}

Error Response (404):

{
  "error": "Product not found",
  "status": 404
}

Delete Product

DELETE

Permanently remove a product from the system by its ID. This action cannot be undone.

DELETE /delete-product/:id

Warning: This action is permanent and cannot be reversed

URL Parameters:

idProduct ID to delete

Example Request:

DELETE http://127.0.0.1:5000/delete-product/3
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

Success Response (200):

{
  "message": "Product deleted successfully",
  "product_id": 3
}

Error Response (404):

{
  "error": "Product not found",
  "status": 404
}

View Users

GET

Retrieve a list of all registered users in the system. Includes user details and account statistics.

GET /view-users

Authentication Required: Admin JWT token

Success Response (200):

{
  "users": [
    {
      "id": 1,
      "username": "john_doe",
      "email": "john@example.com",
      "phone": "+234-803-456-7890",
      "address": "123 Main St, Lagos",
      "total_orders": 12,
      "total_spent": 54300.00,
      "account_status": "active",
      "created_at": "2025-09-15T08:30:00Z",
      "last_login": "2025-10-10T13:25:00Z"
    },
    {
      "id": 2,
      "username": "jane_smith",
      "email": "jane@example.com",
      "phone": "+234-805-234-5678",
      "address": "456 Oak Ave, Abuja",
      "total_orders": 8,
      "total_spent": 32100.00,
      "account_status": "active",
      "created_at": "2025-09-20T11:00:00Z",
      "last_login": "2025-10-09T16:40:00Z"
    }
  ],
  "total_users": 2
}

All Orders

GET

Retrieve a list of all customer orders. Supports optional query parameters for filtering (e.g., by status).

GET /all-orders

Authentication Required: Admin JWT token

Query Parameters (Optional):

Parameter Type Description
statusstringFilter by order status (e.g., "pending", "shipped", "delivered")

Success Response (200):

{
  "orders": [
    {
      "order_id": 101,
      "user_id": 1,
      "username": "john_doe",
      "total_amount": 9100.00,
      "status": "shipped",
      "items": [
        {"product_id": 1, "name": "Premium Rice 5kg", "quantity": 1, "price": 4500.00},
        {"product_id": 2, "name": "Cooking Oil 2L", "quantity": 2, "price": 2800.00}
      ],
      "shipping_address": "123 Main St, Lagos",
      "ordered_at": "2025-10-05T12:00:00Z"
    },
    {
      "order_id": 102,
      "user_id": 2,
      "username": "jane_smith",
      "total_amount": 7500.00,
      "status": "pending",
      "items": [
        {"product_id": 5, "name": "Fresh Tomatoes", "quantity": 5, "price": 1500.00}
      ],
      "shipping_address": "456 Oak Ave, Abuja",
      "ordered_at": "2025-10-10T10:10:00Z"
    }
  ],
  "total_orders": 2
}

Update Order Status

PUT

Update the status of a specific order (e.g., from 'pending' to 'shipped' or 'delivered').

PUT /order-status/:order_id

Authentication Required: Admin JWT token

URL Parameters:

order_idID of the order to update

Request Body:

{
  "status": "shipped"
}

Success Response (200):

{
  "message": "Order status updated successfully",
  "order_id": 102,
  "new_status": "shipped"
}

Error Response (404):

{
  "error": "Order not found",
  "status": 404
}

User Endpoints

Endpoints for customer-facing operations like registration, ordering, and viewing products.

User Signup

POST

Register a new customer account.

POST /signup

Request Body:

{
  "username": "customer_user",
  "email": "customer@test.com",
  "password": "userpass123",
  "phone": "+234-80X-XXX-XXXX",
  "address": "789 Pine Rd, Kano"
}

Success Response (201):

{
  "message": "User account created successfully",
  "user": {
    "id": 3,
    "username": "customer_user",
    "email": "customer@test.com"
  }
}

Error Response (400):

{
  "error": "Email already registered",
  "status": 400
}

User Login

POST

Authenticate a customer and receive a JWT token for accessing protected user endpoints.

POST /login

Request Body:

{
  "email": "customer@test.com",
  "password": "userpass123"
}

Success Response (200):

{
  "message": "Login successful",
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": 3,
    "username": "customer_user",
    "email": "customer@test.com"
  }
}

Error Response (401):

{
  "error": "Invalid credentials",
  "status": 401
}

Browse Products

GET

Retrieve a list of all available products. This endpoint is generally public.

GET /products

Query Parameters (Optional):

Parameter Type Description
categorystringFilter products by category
searchstringSearch products by name or description

Success Response (200):

{
  "products": [
    {
      "id": 1,
      "name": "Premium Rice 5kg",
      "price": 4500.00,
      "category": "Food & Beverages",
      "image_url": "/uploads/rice_5kg.jpg"
      // Note: Stock is often hidden from public view
    },
    {
      "id": 2,
      "name": "Cooking Oil 2L",
      "price": 2800.00,
      "category": "Food & Beverages",
      "image_url": "/uploads/oil_2l.jpg"
    }
  ],
  "total_products": 2
}

Place Order

POST

Create a new order with a list of products and quantities. Requires user authentication.

POST /place-order

Authentication Required: User JWT token

Request Body:

{
  "items": [
    {
      "product_id": 1,
      "quantity": 1
    },
    {
      "product_id": 2,
      "quantity": 2
    }
  ],
  "shipping_address": "123 Main St, Lagos"
}

Success Response (201):

{
  "message": "Order placed successfully",
  "order": {
    "order_id": 103,
    "user_id": 3,
    "total_amount": 9100.00,
    "status": "pending",
    "ordered_at": "2025-10-10T15:30:00Z"
  }
}

Error Response (400 - Insufficient Stock):

{
  "error": "Insufficient stock for product ID: 2",
  "status": 400
}

My Orders

GET

Retrieve a list of all orders placed by the authenticated user.

GET /my-orders

Authentication Required: User JWT token

Success Response (200):

{
  "orders": [
    {
      "order_id": 103,
      "total_amount": 9100.00,
      "status": "pending",
      "items": [
        {"product_id": 1, "name": "Premium Rice 5kg", "quantity": 1, "price": 4500.00},
        {"product_id": 2, "name": "Cooking Oil 2L", "quantity": 2, "price": 2800.00}
      ],
      "ordered_at": "2025-10-10T15:30:00Z"
    },
    {
      "order_id": 98,
      "total_amount": 15000.00,
      "status": "delivered",
      "items": [
        {"product_id": 10, "name": "Smartphone", "quantity": 1, "price": 15000.00}
      ],
      "ordered_at": "2025-10-01T09:00:00Z"
    }
  ],
  "total_orders": 2
}