Item Variants API Documentation
This document describes the item variants endpoint for retrieving paginated lists of item variants in the optical store system. Item variants represent specific configurations of items (e.g., different lens prescriptions, treatments, or colors) and can be searched by barcode or name.Endpoint Details
Base URL:https://joptic.jethings.com
Required Headers
Authentication
All endpoints require user authentication. The user ID is extracted from the JWT token (req.user.sub), and store access is validated via the @StoreId() decorator. Only item variants belonging to products in the authenticated user’s store are returned.
Get All Item Variants
Retrieve a paginated list of item variants for the current store. Supports searching by barcode or item variant name. Endpoint:GET /item-variants
Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
search | string | No | — | Search term to filter by barcode or item variant name |
page | number | No | 1 | Page number (min: 1) |
limit | number | No | 10 | Items per page (min: 1, max: 100) |
Search Functionality
The search parameter performs a case-insensitive search across:- Barcodes: Searches in the barcode table and returns item variants associated with matching barcodes
- Item Variant Names: Searches directly in item variant names
When searching, the system searches both barcodes and item variant names in parallel for optimal performance. Results are combined and deduplicated. If no matches are found, an empty array is returned with pagination metadata.
Success Response
Response Fields
id(string) - Unique identifier for the item variantname(string | null) - Name of the item variant (e.g., “1.50 PhGy BB +0.00 +0.25”)description(string | null) - Optional description of the item variantisActive(boolean) - Whether the item variant is currently activecreatedAt(Date) - Timestamp when the item variant was createdupdatedAt(Date) - Timestamp when the item variant was last updated
Pagination Fields
page(number) - Current page numberlimit(number) - Number of items per pagetotal(number) - Total number of item variants matching the criteriatotalPages(number) - Total number of pages availablehasNext(boolean) - Whether a next page existshasPrev(boolean) - Whether a previous page exists
Results are paginated for performance. Default sorting is by creation date (newest first). Only non-deleted item variants (
deletedAt IS NULL) belonging to products in the authenticated user’s store are returned.Example Request
Example: Search by Barcode
Example: Search by Name
Example: Get All Variants (No Search)
Possible Errors
401 Unauthorized- Missing or invalid authentication token403 Forbidden- User does not have access to the store500 Internal Server Error- Server error
Business Logic
Item Variant Retrieval Process
Store Filtering
Store Filtering
Store FilteringThe system automatically filters item variants by:
- Joining item variants with items and products
- Filtering products by the authenticated user’s store ID
- Ensuring only variants from accessible stores are returned
Search Implementation
Search Implementation
Search ImplementationWhen a search term is provided, the system:
- Searches barcodes in parallel with item variant names
- Finds matching barcodes and retrieves associated item variant IDs
- Finds matching item variant names directly
- Combines and deduplicates results
- Filters the final results by store and deletion status
Soft Delete Handling
Soft Delete Handling
Soft Delete HandlingThe system automatically excludes deleted item variants:
- Only variants where
deletedAt IS NULLare returned - Deleted variants are permanently excluded from results
- This ensures data integrity and prevents access to archived items
Pagination
Pagination
PaginationPagination is enforced with:
- Minimum page: 1
- Minimum limit: 1
- Maximum limit: 100
- Default values: page=1, limit=10
- Results are ordered by creation date (newest first)
Barcode Association
Barcode Association
Barcode AssociationWhen searching by barcode:
- The system finds matching barcodes in the barcode table
- Retrieves item variant IDs from the barcode-item association table
- Only active barcode associations (
isActive = true) are considered - Results are combined with name-based search results
Item Variant States
Active Variants
Active (
Variant is currently available for use in inventory and sales
isActive: true)Variant is currently available for use in inventory and sales
Inactive Variants
Inactive (
Variant exists but is not currently available
isActive: false)Variant exists but is not currently available
Deleted Variants
Deleted (
Soft-deleted variants are excluded from all queries
deletedAt IS NOT NULL)Soft-deleted variants are excluded from all queries
Barcode Linked
Barcode Association
Variants can be found by searching associated barcodes
Variants can be found by searching associated barcodes
Error Responses
All endpoints may return standard HTTP error codes:401 Unauthorized- Missing or invalid authentication token403 Forbidden- User does not have access to the store500 Internal Server Error- Server error
Error Response Format
Common Error Scenarios
403 Forbidden - Store AccessUsage Examples
Example 1: Get all item variants with default pagination
Example 2: Search by barcode
Example 3: Search by item variant name
Example 4: Get second page with custom limit
Example 5: Search with pagination
Best Practices
Search Optimization
Search Optimization
- Use specific search terms for better performance
- Barcode searches are faster than name searches
- Combine search with pagination for large result sets
- Use appropriate limit values (10-50 for most cases)
Pagination
Pagination
- Use default pagination (page=1, limit=10) for most use cases
- Increase limit (max 100) only when necessary
- Always check
hasNextandhasPrevfor navigation - Implement proper error handling for invalid page numbers
Barcode Usage
Barcode Usage
- Use barcode search for point-of-sale scenarios
- Ensure barcodes are properly associated with item variants
- Handle cases where barcode might not be found
- Consider implementing barcode scanning in your application
Error Handling
Error Handling
- Always check for 403 errors when accessing store data
- Handle empty search results gracefully
- Implement retry logic for 500 errors with exponential backoff
- Validate pagination parameters before making requests
Performance
Performance
- Cache frequently accessed item variants when possible
- Use search filters to reduce result set size
- Avoid fetching all variants without pagination
- Consider implementing client-side filtering for small datasets
Data Consistency
Data Consistency
- Be aware that deleted variants are automatically excluded
- Check
isActivestatus for availability - Handle null values for
nameanddescriptionfields - Verify store access before displaying results to users
Related Endpoints
Item variants work in conjunction with other inventory management endpoints:- Item API (
/items) - Create and manage items that contain variants - Item CRUD API (
/items) - Update item variants and their properties - Stock Reconciliation API (
/stock-reconciliation) - Reconcile inventory for specific item variants - Price List API (
/price-lists) - Set prices for item variants
Item variants are automatically created when items are created. Use the Item API to create new items with variants, and use this endpoint to search and retrieve existing variants.
Summary
| Endpoint | Method | Description |
|---|---|---|
/item-variants | GET | Retrieve paginated list of item variants with optional search |
Key Features
- Search by Barcode: Find item variants by scanning or entering barcodes
- Search by Name: Find item variants by name (case-insensitive)
- Pagination: Efficient data retrieval with configurable page size
- Store Filtering: Automatic filtering by authenticated user’s store
- Soft Delete: Deleted variants are automatically excluded