Products API
Product Management
Create and retrieve products in the recommendation system.
Create Products
Upload multiple products at once for a customer.
Endpoint
POST /api/products/upload
Authentication
Required: JWT Bearer token
Request Body
[
{
"customer_id": "customer_123",
"name": "Wireless Headphones",
"description": "High-quality Bluetooth headphones with noise cancellation",
"price": 199.99
},
{
"customer_id": "customer_123",
"name": "Smart Watch",
"description": "Fitness tracking and notifications",
"price": 299.99
}
]
Request Fields
| Field | Type | Required | Description |
|---|---|---|---|
| customer_id | string | Yes | Customer identifier (must match authenticated user) |
| name | string | Yes | Product name |
| description | string | No | Product description |
| price | float | Yes | Product price |
Response
{
"product_ids": [
"64a1b2c3d4e5f6789012345",
"64a1b2c3d4e5f6789012346"
]
}
Error Responses
400 Bad Request
{
"detail": "Product customer_id customer_456 does not match customer_id customer_123"
}
400 Bad Request
{
"detail": "Error creating products: Database connection failed"
}
Get Products
Retrieve products by ID or get all products for the authenticated customer.
Endpoint
GET /api/products/get
Authentication
Required: JWT Bearer token
Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| product_id | string | No | - | Specific product ID to retrieve |
| limit | integer | No | 100 | Maximum number of products to return |
Response
[
{
"product_id": "64a1b2c3d4e5f6789012345",
"customer_id": "customer_123",
"name": "Wireless Headphones",
"description": "High-quality Bluetooth headphones with noise cancellation",
"price": 199.99,
"created_at": "2023-07-01T14:30:00.000Z"
}
]
Response Fields
| Field | Type | Description |
|---|---|---|
| product_id | string | Unique product identifier |
| customer_id | string | Customer who owns the product |
| name | string | Product name |
| description | string | Product description (if provided) |
| price | float | Product price |
| created_at | string | ISO timestamp of creation |
Error Responses
404 Not Found
{
"detail": "Product not found"
}
500 Internal Server Error
{
"detail": "Database connection error"
}
Example Usage
Create Products
curl -X POST "http://localhost:5051/api/products/upload" \
-H "Authorization: Bearer <jwt-token>" \
-H "Content-Type: application/json" \
-d '[
{
"customer_id": "customer_123",
"name": "Laptop Stand",
"description": "Adjustable aluminum laptop stand",
"price": 49.99
}
]'
Get All Products
curl -X GET "http://localhost:5051/api/products/get" \
-H "Authorization: Bearer <jwt-token>"
Get Specific Product
curl -X GET "http://localhost:5051/api/products/get?product_id=64a1b2c3d4e5f6789012345" \
-H "Authorization: Bearer <jwt-token>"
Data Storage
Products are stored in MongoDB with the following structure:
- Collection:
products - Indexing: Automatic indexing on
product_idandcustomer_id - Metadata: Each product includes creation timestamp and batch information
Security Notes
- Products can only be created for the authenticated customer's ID
- All product operations are logged for audit purposes
- MongoDB connection uses secure connection strings from environment variables