Skip to main content
POST
/
api
/
product
/
user
/
add
Add Product to Inventory
curl --request POST \
  --url https://api.example.com/api/product/user/add \
  --header 'Content-Type: application/json' \
  --data '
{
  "name": "<string>",
  "quantity": 123,
  "category": "<string>",
  "expiryDate": "<string>",
  "notes": "<string>",
  "isScannedProduct": true
}
'
{
  "message": "<string>",
  "productId": "<string>",
  "name": "<string>",
  "quantity": 123,
  "expiryDate": "<string>"
}

Overview

This endpoint adds a product to the authenticated user’s inventory. It supports two modes:
  • Barcode scanning: Provide a barcode query parameter to automatically fetch product details
  • Manual entry: Provide product details in the request body

Authentication

This endpoint requires authentication. The user’s access token must be included in the request and contains the userId extracted from request.state.user.

Expiry Date Calculation

The endpoint automatically calculates expiry dates based on the input method:
  • Barcode scanning (barcode parameter provided): Sets expiry to 20 seconds from current time (for testing purposes)
  • Scanned product (isScannedProduct: true): Calculates expiry based on product shelf life (fetched from product database)
  • Manual entry: Sets expiry to 10 seconds from current time (default behavior)

Request

Query Parameters

barcode
string
The barcode of the product to scan. When provided, the product name is automatically fetched from the database, and quantity is set to 1.

Body Parameters

name
string
Name of the product. Required when barcode is not provided.
quantity
integer
default:1
Quantity of the product to add.
category
string
default:"Uncategorized"
Category of the product.
expiryDate
string
ISO 8601 formatted expiry date. If not provided, it will be calculated automatically.
notes
string
Additional notes about the product.
isScannedProduct
boolean
default:false
Indicates if the product was scanned (triggers shelf life calculation and notifications).

Response

message
string
Success message confirming the product was added.
productId
string
The ID of the product in the product inventory.
name
string
Name of the product that was added.
quantity
integer
Quantity of the product added.
expiryDate
string
ISO 8601 formatted expiry date of the product.

Examples

Add Product via Barcode

curl -X POST "https://api.expireeye.com/api/product/user/add?barcode=1234567890" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{}'

Add Product Manually

curl -X POST "https://api.expireeye.com/api/product/user/add" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Organic Eggs",
    "quantity": 2,
    "category": "Dairy",
    "notes": "Store in refrigerator",
    "isScannedProduct": false
  }'

Add Scanned Product with Shelf Life

curl -X POST "https://api.expireeye.com/api/product/user/add" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Fresh Bread",
    "quantity": 1,
    "category": "Bakery",
    "isScannedProduct": true
  }'

Error Responses

Barcode Not Found

{
  "detail": "Product not found for the provided barcode"
}
Status Code: 404

User Not Found

{
  "detail": "User with the provided userId does not exist."
}
Status Code: 404

Behavior Notes

  1. Auto-create Products: If the product doesn’t exist in the main product inventory, it will be automatically created with category “Uncategorized”
  2. Notifications: When isScannedProduct: true, the system sends a real-time notification to the user with product details and nutrition information
  3. Notes Auto-generation: When using barcode scanning, notes are automatically set to “Scanned Via Barcode with Code

Build docs developers (and LLMs) love