Skip to main content

Warehouse API

The Warehouse API provides endpoints for managing warehouses and their hierarchical structure, addresses, and contact information within stores.
All Warehouse API endpoints require authentication and a valid x-store-id header to identify the store context, unless stated otherwise.

Overview

Warehouses can be:
  • Created with required address information and optional contact details
  • Organized in hierarchical structures using parent-child relationships
  • Filtered and sorted by various criteria
  • Retrieved in paginated lists or individually by ID
  • Updated with partial updates for flexible editing
  • Deleted when no longer needed

Endpoint Details

Base URL: https://jethings-backend.fly.dev
Content-Type: application/json

Required Headers

All routes require a valid x-store-id header. Users must have an active relation with the store to access its warehouses.

Get All Warehouses

GET /warehouses Retrieve a paginated list of warehouses for the store that the authenticated user has access to. Requires Authentication: Bearer token in Authorization header

Required Headers

Query Parameters

Success Response

Status Code: 200 OK

Response Fields

Warehouse Object

Pagination Object

Possible Errors

Example Requests

Search warehouses by name:
Filter by parent warehouse:

Get Single Warehouse

GET /warehouses/:id Retrieve a single warehouse by its ID. Requires Authentication: Bearer token in Authorization header

Path Parameters

Success Response

Status Code: 200 OK

Response Fields

Same as the warehouse object in the “Get All Warehouses” endpoint.

Possible Errors

Example Requests


Create Warehouse

POST /warehouses Create a new warehouse with address information and optional contact details. Requires Authentication: Bearer token in Authorization header

Required Headers

Request Body

Request Body Example

Success Response

Status Code: 201 Created

Possible Errors

Example Requests

When creating a warehouse, the system automatically:
  1. Creates an address record with the provided address information
  2. Creates a contact record if phone, email, or contactPerson is provided
  3. Links the warehouse to the authenticated user’s store
  4. Sets isGrouped to true if parentId is provided, otherwise false

Update Warehouse

PUT /warehouses/:id Update an existing warehouse. Supports partial updates - only provided fields will be updated. Requires Authentication: Bearer token in Authorization header

Path Parameters

Request Body

All fields are optional (partial updates supported):

Request Body Example

Success Response

Status Code: 200 OK

Possible Errors

Example Requests

When updating a warehouse:
  • Only provided fields are updated (partial updates supported)
  • Address fields are updated in the linked address record
  • Contact fields are updated in the linked contact record, or a new contact record is created if one doesn’t exist
  • Setting parentId to null removes the parent relationship
  • The updatedAt timestamp is automatically updated

Delete Warehouse

DELETE /warehouses/:id Delete a warehouse by its ID. This is a permanent deletion. Requires Authentication: Bearer token in Authorization header

Path Parameters

Success Response

Status Code: 200 OK

Possible Errors

Example Requests

This operation permanently deletes the warehouse. Make sure to verify the warehouse ID before deletion. Consider checking for dependent records (like inventory items) before deleting.

Business Logic

Warehouse Creation Flow

Address ManagementWhen creating a warehouse:
  1. A new address record is always created with the provided address information
  2. All address fields (street, city, state, country, postalCode) are required
  3. The address is automatically linked to the warehouse via addressId
  4. Address can be updated independently when updating the warehouse
Contact ManagementContact information is optional:
  1. A contact record is only created if at least one contact field (phone, email, contactPerson) is provided
  2. If contact is provided, it’s automatically linked to the warehouse via contactId
  3. When updating, if contact doesn’t exist and contact fields are provided, a new contact record is created
  4. Contact fields can be updated independently of other warehouse fields
Hierarchical StructureWarehouses can be organized hierarchically:
  1. Set parentId to create a child warehouse under a parent
  2. isGrouped is automatically set to true if parentId exists, false otherwise
  3. Useful for organizing warehouses by location, type, or business unit
  4. Filter by parentId to get all child warehouses of a specific parent
  5. Set parentId to null to remove the parent relationship
Store Access ValidationAccess control is enforced:
  1. User must have an active relation with the store to access its warehouses
  2. Store access is validated on every request
  3. Users can only create/update/delete warehouses for stores they have access to
  4. Warehouse operations are scoped to the authenticated user’s accessible stores
Partial UpdatesThe update endpoint supports flexible partial updates:
  1. Only provided fields are updated
  2. Address fields can be updated independently
  3. Contact fields can be updated independently
  4. Warehouse fields (name, parentId) can be updated independently
  5. This allows fine-grained control over what gets updated

Warehouse States

Active Warehouse

Active (isActive: true)
Warehouse is currently in use and available for operations

Grouped Warehouse

Grouped (isGrouped: true)
Warehouse has a parent warehouse (part of hierarchical structure)

Standalone Warehouse

Standalone (isGrouped: false)
Warehouse has no parent (top-level warehouse)

With Contact

Contact Information
Warehouse has associated contact details (phone, email)

Error Responses

All endpoints may return standard HTTP error codes:
  • 400 Bad Request - Invalid request parameters or body
  • 403 Forbidden - User does not have access to the store or warehouse
  • 404 Not Found - Resource not found (warehouse, store, etc.)
  • 500 Internal Server Error - Server error

Error Response Format

Common Error Scenarios

403 Forbidden - Store Access
Occurs when the user doesn’t have an active relation with the specified store. 404 Not Found - Warehouse
Occurs when the warehouse ID doesn’t exist or doesn’t belong to an accessible store. 400 Bad Request - Validation Error
Occurs when required fields are missing or data types are incorrect.

Usage Examples

Example 1: Create a top-level warehouse

Example 2: Create a child warehouse

Example 3: Get warehouses with filtering

Example 4: Update warehouse address only

Example 5: Remove parent relationship


Best Practices

  • Use hierarchical structure to organize warehouses by location or business unit
  • Create top-level warehouses for major locations
  • Use child warehouses for branches or sub-locations
  • Keep warehouse names descriptive and consistent
  • Always provide complete address information for accurate location tracking
  • Use consistent address formats across warehouses
  • Update addresses when warehouses relocate
  • Validate postal codes match the country format
  • Provide contact information for easy communication
  • Keep email addresses up to date for notifications
  • Include phone numbers for urgent matters
  • Update contact information when personnel changes
  • Use pagination when fetching large lists of warehouses
  • Default limit of 10 is suitable for most use cases
  • Maximum limit of 100 should be used sparingly
  • Always check hasNext and hasPrev for navigation
  • Use search for general name searches
  • Use name for specific name filtering
  • Use parentId to get all child warehouses
  • Combine filters for precise results
  • Only send fields that need to be updated
  • Update address and contact information independently when possible
  • Use partial updates to avoid overwriting unchanged data
  • Verify warehouse ID before updating
  • Verify warehouse ID before deletion
  • Check for dependent records (inventory, stock reconciliations) before deleting
  • Consider the impact on child warehouses before deleting a parent
  • Deletion is permanent and cannot be undone

Warehouses work in conjunction with other inventory management endpoints:
  • Stock Reconciliation API (/stock-reconciliation) - Reconcile inventory for specific warehouses
  • Purchase Invoice API (/purchase-invoices) - Create purchase invoices linked to warehouses
  • Purchase Order API (/purchase-orders) - Create purchase orders for warehouses
Warehouses are essential for inventory management. They represent physical locations where inventory is stored and managed. Use warehouses to organize your inventory by location and track stock movements.

Summary


Stock Reconciliation API

Reconcile inventory for warehouses

Purchase Invoice API

Create purchase invoices for warehouses