0% found this document useful (0 votes)
4 views4 pages

E-Commerce API - Admin Only Documentation

This document outlines the admin-only endpoints of the E-Commerce API, which allow administrators to manage users, products, and orders. All routes require authentication via a JWT token with admin privileges. Key functionalities include retrieving user and order lists, updating user roles, and managing product details.

Uploaded by

Husain ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

E-Commerce API - Admin Only Documentation

This document outlines the admin-only endpoints of the E-Commerce API, which allow administrators to manage users, products, and orders. All routes require authentication via a JWT token with admin privileges. Key functionalities include retrieving user and order lists, updating user roles, and managing product details.

Uploaded by

Husain ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

E-Commerce API - Admin Only

Documentation
Overview
This document provides details on the admin-only endpoints available in the E-Commerce API.
These routes allow administrators to manage users, products, and orders within the platform. All
admin routes require authentication and authorization using a JWT token with admin privileges.

1. User Management
GET /api/users/all

Description: Retrieves a list of all registered users.

Response:

[
{ /* user data */ },
{ /* user data */ }
]

PUT /api/users/:id/role

Description: Updates a user's role (e.g., promoting to admin).

Request Body:

{
"role": "admin"
}

Response:

{
"message": "User role updated",
"user": { /* updated user data */ }
}
2. Product Management
POST /api/products

Description: Adds a new product to the platform.

Request Body:

{
"name": "Product Name",
"price": 100,
"description": "Product Description"
}

Response:

{
"id": 1,
"name": "Product Name",
"price": 100,
"description": "Product Description"
}

PUT /api/products/:id

Description: Updates an existing product.

Request Body:

{
"name": "Updated Product Name",
"price": 120,
"description": "Updated Description"
}

Response:

{
"id": 1,
"name": "Updated Product Name",
"price": 120,
"description": "Updated Description"
}

DELETE /api/products/:id
Description: Deletes a product from the platform.

Response:

{
"message": "Product deleted"
}

3. Order Management
GET /api/orders

Description: Retrieves a list of all orders placed by users.

Response:

[
{ /* order data */ },
{ /* order data */ }
]

PUT /api/orders/:id

Description: Updates the status of an order (e.g., marking it as shipped).

Request Body:

{
"status": "shipped"
}

Response:

{
"id": 1,
"userId": 1,
"totalAmount": 200,
"status": "shipped"
}

Authentication & Security


All admin routes require authentication and role-based access control (RBAC). Ensure that
requests include a valid JWT token with admin privileges.

Middleware Used:

●​ authenticate: Ensures the user is logged in by verifying the JWT token.


●​ authorize("admin"): Restricts access to admin users only.

Summary of Admin-Only Routes


●​ User Management
○​ GET /api/users/all - View all users.
○​ PUT /api/users/:id/role - Update user roles.
●​ Product Management
○​ POST /api/products - Add a product.
○​ PUT /api/products/:id - Update a product.
○​ DELETE /api/products/:id - Delete a product.
●​ Order Management
○​ GET /api/orders - View all orders.
○​ PUT /api/orders/:id - Update order status.

This document serves as a reference for administrators managing the e-commerce platform.
Ensure all API calls include the appropriate authentication headers.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy