Stock Reconciliation API
Created: December 25, 2025This documentation provides comprehensive information about the stock reconciliation endpoint, including multi-item support, asynchronous processing, and complete workflow examples.
Endpoint Details
Base URL:https://joptic.jethings.com
Required Headers
Endpoint
Create Stock Reconciliation
Request
Method:POSTPath:
/stock-reconciliation
Headers
| Header | Type | Required | Description |
|---|---|---|---|
x-store-id | string | ✅ Yes | The store ID |
Authorization | string | ✅ Yes | Bearer token for authentication |
Content-Type | string | ✅ Yes | application/json |
Request Body
Type:CreateReconciliationDto
Field Descriptions
Items Array
| Field | Type | Required | Description |
|---|---|---|---|
items | array | ✅ Yes | Array of items to reconcile (minimum 1 item required) |
items[].warehouse | string | ✅ Yes | The warehouse ID where the reconciliation is performed |
items[].itemVariant | string | ✅ Yes | The item variant ID being reconciled |
items[].actualQty | number | ✅ Yes | The actual physical quantity counted during inventory |
Note
| Field | Type | Required | Description |
|---|---|---|---|
note | string | No | Optional note or reason for the reconciliation (e.g., “Monthly inventory check”, “Damaged goods adjustment”). This note is shared across all items in the request and will be stored in both the reconciliation record and the stock ledger entry. |
Validation Rules
- At least one item must be provided in the
itemsarray - Each item must have valid
warehouse,itemVariant, andactualQtyfields actualQtymust be a number (can be positive, negative, or zero)
Response
Type:CreateStockReconciliationResponseDto
Field Descriptions
| Field | Type | Description |
|---|---|---|
data | array | Array of created reconciliation records |
data[].id | string | Unique identifier for the reconciliation record |
data[].note | string | null | The note provided in the request (shared across all items) |
data[].systemQty | string | The system-recorded quantity at the time of reconciliation (sum of all active bins for the warehouse/itemVariant) |
data[].actualQty | string | The physical quantity that was counted |
data[].differenceQty | string | Calculated as actualQty - systemQty |
data[].createdAt | Date | When the reconciliation record was created |
data[].updatedAt | Date | When the reconciliation record was last updated |
- Positive: More items found than system shows (surplus)
- Negative: Fewer items found than system shows (shortage)
- Zero: Perfect match
How It Works
1. Transaction Processing
All items are processed within a single database transaction to ensure atomicity. If any item fails, the entire operation is rolled back.2. For Each Item
Step 1: Calculate System Quantity
The system retrieves the current system quantity from the bin table:- Only active bins are included in the calculation
- If no bins exist, system quantity defaults to
0 - The sum accounts for all active bins for the warehouse/itemVariant combination
Step 2: Calculate Difference
- System: 100, Actual: 98 → Difference: -2 (shortage)
- System: 50, Actual: 55 → Difference: +5 (surplus)
- System: 0, Actual: 10 → Difference: +10 (new stock found)
Step 3: Create Reconciliation Record
AstockReconciliation record is created with:
- Warehouse ID
- Item variant ID
- System quantity (as string for precision)
- Actual quantity (as string for precision)
- Difference quantity (as string for precision)
- Note (shared across all items)
Step 4: Queue Stock Update Job
A background job is queued to update the stock ledger entry and bin table. The job runs asynchronously and includes:- Reconciliation ID
- Warehouse ID
- Item variant ID
- Actual quantity
- Note
3. Asynchronous Stock Update (Background Job)
After the transaction commits, the queued job processes each reconciliation:Stock Ledger Entry (SLE)
Creates a stock ledger entry for audit trail:The
qtyChange is always 0 for reconciliations because we’re setting an absolute quantity, not making a relative change.Bin Update
Updates or creates the bin entry:- If bin exists: Updates the bin’s
qtyto matchactualQty - If bin doesn’t exist: Creates a new bin entry with
qty = actualQtyandisActive = true
Stock updates are processed asynchronously via a queue system. The endpoint returns immediately after creating reconciliation records. Background jobs process stock updates. Jobs have retry logic (3 attempts by default). If a job fails, it remains in the queue for manual review.
4. Response Mapping
All created reconciliation records are mapped to response DTOs and returned in the response array.Example Requests
Single Item Reconciliation
- System quantity: 100
- Actual quantity: 98
- Difference: -2 (shortage)
Multiple Items Reconciliation
- All three items are processed in a single transaction
- Each item gets its own reconciliation record
- All records share the same note
- Three separate background jobs are queued (one per item)
New Stock Found (No Previous Bin)
- System quantity: 0 (no bin exists)
- Actual quantity: 25
- Difference: +25
- Result: New bin entry is created with qty = 25
Zero Quantity Reconciliation
- System quantity: 5
- Actual quantity: 0
- Difference: -5 (all items missing)
- Result: Bin is updated to qty = 0
Example Responses
Success Response (Single Item)
Success Response (Multiple Items)
When multiple items are reconciled, each gets its own record in the response array:Error Responses
400 Bad Request
Validation Errors
-
Empty items array:
"At least one item is required"- Occurs when
itemsarray is empty or not provided
- Occurs when
-
Missing required fields: Validation errors for missing
warehouse,itemVariant, oractualQty"warehouse must be a string""warehouse should not be empty""itemVariant must be a string""itemVariant should not be empty""actualQty must be a number"
500 Internal Server Error
- Database transaction failures
- Queue processing errors
- Foreign key constraint violations (invalid warehouse or itemVariant IDs)
Important Notes
1. Atomic Transaction
All items in a single request are processed within one database transaction. This means:- All succeed or all fail: If any item fails validation or processing, the entire request is rolled back
- Consistent state: You won’t have partial reconciliations
2. System Quantity Calculation
The system quantity is calculated as:- Sum of all active bins for the warehouse/itemVariant combination
- Only bins where
isActive = trueare included - If no active bins exist, system quantity is
0
3. Difference Calculation
- Positive difference: More items found than system shows (surplus)
- Negative difference: Fewer items found than system shows (shortage)
- Zero difference: Perfect match
4. Asynchronous Stock Updates
Stock ledger entries and bin updates happen asynchronously via a queue system:- The endpoint returns immediately after creating reconciliation records
- Background jobs process stock updates
- Jobs have retry logic (3 attempts by default)
- If a job fails, it remains in the queue for manual review
5. Bin Quantity Update
The bin quantity is set to the absolute actual quantity, not adjusted by the difference:- Before reconciliation: Bin qty = 100
- Actual count: 98
- After reconciliation: Bin qty = 98 (not 100 - 2)
6. Stock Ledger Entry
Every reconciliation creates a stock ledger entry for audit purposes:qtyChangeis always0(reconciliation sets absolute quantity, not relative)qtyAfterTransactionis set to the actual quantityvoucherTypeis"stock_reconciliation"voucherlinks to the reconciliation record IDreasoncontains the note from the reconciliation
7. Shared Note
Thenote field is shared across all items in a single request. If you need different notes for different items, make separate requests.
8. Decimal Precision
All quantities are stored as strings (decimal type in database) to maintain precision. The response returns them as strings to preserve exact values.9. Multiple Warehouses
You can reconcile items from different warehouses in a single request. Each item specifies its own warehouse.10. New Stock Creation
If an item variant doesn’t have a bin entry, the reconciliation will:- Create a new bin entry with the actual quantity
- Set
isActive = true - Create a stock ledger entry documenting the new stock
Workflow Example
Typical Inventory Reconciliation Process
-
Physical Count
- Staff counts physical inventory in the warehouse
- Records actual quantities for each item variant
-
Create Reconciliation
-
System Processing
- System calculates current quantity: 100
- Calculates difference: -2
- Creates reconciliation record
- Queues background job
-
Background Job Execution
- Creates stock ledger entry (qtyChange=0, qtyAfterTransaction=98)
- Updates bin quantity to 98
- Job completes successfully
-
Verification
- Check reconciliation record via GET endpoint
- Verify bin quantity was updated
- Review stock ledger entry for audit trail
Integration with Other Systems
Stock Ledger
Every reconciliation creates a stock ledger entry:- Provides complete audit trail
- Links to reconciliation record via
voucherfield - Can be queried to see all stock adjustments
Bin Management
Bin quantities are automatically updated:- Reflects actual physical counts
- Maintains accurate inventory levels
- Supports multi-warehouse scenarios
Reporting
Reconciliation records can be queried via:GET /stock-reconciliation- List all reconciliations with pagination- Filter by warehouse, item variant, date range
- Analyze discrepancies over time
Database Schema
stockReconciliation Table
stockLedgerEntry (Created by Background Job)
bin (Updated by Background Job)
Related Endpoints
GET /stock-reconciliation- Get paginated list of all reconciliations- Supports search, pagination, and sorting
- Filters by store (via warehouse relationship)
Best Practices
- Batch Related Items: Group items from the same warehouse or reconciliation session in a single request for better performance and consistency.
- Use Descriptive Notes: Always provide meaningful notes to explain why the reconciliation was performed (e.g., “Monthly inventory”, “Damaged goods adjustment”, “Theft investigation”).
- Verify Before Reconciling: Check system quantities before performing reconciliation to understand expected differences.
- Monitor Background Jobs: Ensure the queue processor is running to complete stock updates. Check job status if bin quantities aren’t updating.
- Regular Reconciliation: Perform regular inventory counts to maintain accurate stock levels and identify discrepancies early.
- Document Discrepancies: Use the note field to document reasons for significant differences (theft, damage, counting errors, etc.).
- Review Stock Ledger: Regularly review stock ledger entries to track all inventory adjustments and maintain audit trail.