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

Authorization: Bearer <token>
x-store-id: <store_id>
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

KeyValueRequiredDescription
x-store-idstringYesStore identifier (used by @StoreId() decorator)

Query Parameters

ParameterTypeRequiredDescriptionDefault
searchstringNoFilter by warehouse name (partial match)
namestringNoFilter by specific warehouse name (partial match)
parentIdstringNoFilter by parent warehouse ID (for hierarchical filtering)
isActivebooleanNoFilter by active/inactive status
pagenumberNoPage number (1-based)1
limitnumberNoNumber of items per page (1–100)10
sortBystringNoSort field (id, name, isActive, updatedAt, createdAt)createdAt
sortOrderstringNoSort direction (asc or desc)desc

Success Response

Status Code: 200 OK
{
  "data": [
    {
      "id": "warehouse_123",
      "storeId": "store_456",
      "parentId": null,
      "name": "Main Warehouse",
      "email": "[email protected]",
      "isActive": true,
      "isGrouped": false,
      "createdAt": "2024-01-15T10:30:00.000Z",
      "updatedAt": "2024-01-15T10:30:00.000Z"
    },
    {
      "id": "warehouse_124",
      "storeId": "store_456",
      "parentId": "warehouse_123",
      "name": "North Branch",
      "email": "[email protected]",
      "isActive": true,
      "isGrouped": true,
      "createdAt": "2024-01-16T09:20:00.000Z",
      "updatedAt": "2024-01-16T09:20:00.000Z"
    }
  ],
  "pagination": {
    "page": 1,
    "limit": 10,
    "total": 25,
    "totalPages": 3,
    "hasNext": true,
    "hasPrev": false
  }
}

Response Fields

Warehouse Object

FieldTypeDescription
idstringUnique warehouse ID
storeIdstringID of the store that owns this warehouse
parentIdstring?ID of the parent warehouse (for hierarchical structure)
namestringWarehouse display name
emailstring?Email address of the warehouse
isActivebooleanActive status
isGroupedbooleanWhether the warehouse is grouped (has a parent)
createdAtstringCreation timestamp (ISO 8601)
updatedAtstringLast update timestamp (ISO 8601)

Pagination Object

FieldTypeDescription
pagenumberCurrent page number
limitnumberNumber of items per page
totalnumberTotal number of records
totalPagesnumberTotal pages available
hasNextbooleanWhether a next page exists
hasPrevbooleanWhether a previous page exists

Possible Errors

CodeMessage
403Forbidden - User does not have access to store
500Internal Server Error

Example Requests

curl -X GET "https://jethings-backend.fly.dev/warehouses?page=1&limit=10" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "x-store-id: store_id_here"
Search warehouses by name:
curl -X GET "https://jethings-backend.fly.dev/warehouses?search=main&page=1&limit=20" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "x-store-id: store_id_here"
Filter by parent warehouse:
curl -X GET "https://jethings-backend.fly.dev/warehouses?parentId=warehouse_123" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "x-store-id: store_id_here"

Get Single Warehouse

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

Path Parameters

ParameterTypeRequiredDescription
idstring✅ YesWarehouse ID

Success Response

Status Code: 200 OK
{
  "id": "warehouse_123",
  "storeId": "store_456",
  "parentId": null,
  "name": "Main Warehouse",
  "email": "[email protected]",
  "isActive": true,
  "isGrouped": false,
  "createdAt": "2024-01-15T10:30:00.000Z",
  "updatedAt": "2024-01-15T10:30:00.000Z"
}

Response Fields

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

Possible Errors

CodeMessage
404Not Found - Warehouse not found
500Internal Server Error

Example Requests

curl -X GET "https://jethings-backend.fly.dev/warehouses/warehouse_123" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"

Create Warehouse

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

Required Headers

KeyValueRequiredDescription
x-store-idstringYesStore identifier (used by @StoreId() decorator)

Request Body

FieldTypeRequiredDescription
namestring✅ YesWarehouse name (max 255 characters)
parentIdstringNoID of parent warehouse (for hierarchical structure)
streetstring✅ YesStreet address (max 500 characters)
citystring✅ YesCity (max 100 characters)
statestring✅ YesState or province (max 100 characters)
countrystring✅ YesCountry (max 100 characters)
postalCodestring✅ YesPostal or ZIP code (max 20 characters)
contactPersonstringNoContact person name (max 255 characters)
phonestringNoPhone number (max 50 characters)
emailstringNoEmail address (max 255 characters, must be valid email)

Request Body Example

{
  "name": "Main Warehouse",
  "parentId": null,
  "street": "123 Industrial Boulevard",
  "city": "New York",
  "state": "NY",
  "country": "United States",
  "postalCode": "10001",
  "contactPerson": "John Smith",
  "phone": "+1-555-123-4567",
  "email": "[email protected]"
}

Success Response

Status Code: 201 Created
{
  "id": "warehouse_123",
  "storeId": "store_456",
  "parentId": null,
  "name": "Main Warehouse",
  "email": "[email protected]",
  "isActive": true,
  "isGrouped": false,
  "createdAt": "2024-01-15T10:30:00.000Z",
  "updatedAt": "2024-01-15T10:30:00.000Z"
}

Possible Errors

CodeMessage
400Bad Request - Validation errors
403Forbidden - User does not have access to store
404Not Found - Store not found
500Internal Server Error

Example Requests

curl -X POST "https://jethings-backend.fly.dev/warehouses" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "x-store-id: store_id_here" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Main Warehouse",
    "street": "123 Industrial Boulevard",
    "city": "New York",
    "state": "NY",
    "country": "United States",
    "postalCode": "10001",
    "phone": "+1-555-123-4567",
    "email": "[email protected]"
  }'
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

ParameterTypeRequiredDescription
idstring✅ YesWarehouse ID

Request Body

All fields are optional (partial updates supported):
FieldTypeRequiredDescription
namestringNoWarehouse name (max 255 characters)
parentIdstringNoID of parent warehouse (set to null to remove parent)
streetstringNoStreet address (max 500 characters)
citystringNoCity (max 100 characters)
statestringNoState or province (max 100 characters)
countrystringNoCountry (max 100 characters)
postalCodestringNoPostal or ZIP code (max 20 characters)
phonestringNoPhone number (max 50 characters)
emailstringNoEmail address (max 255 characters, must be valid email)

Request Body Example

{
  "name": "Updated Warehouse Name",
  "city": "Los Angeles",
  "state": "CA",
  "email": "[email protected]"
}

Success Response

Status Code: 200 OK
{
  "id": "warehouse_123",
  "storeId": "store_456",
  "parentId": null,
  "name": "Updated Warehouse Name",
  "email": "[email protected]",
  "isActive": true,
  "isGrouped": false,
  "createdAt": "2024-01-15T10:30:00.000Z",
  "updatedAt": "2024-01-15T11:45:00.000Z"
}

Possible Errors

CodeMessage
400Bad Request - Validation errors
403Forbidden - User does not have access to warehouse
404Not Found - Warehouse not found
500Internal Server Error

Example Requests

curl -X PUT "https://jethings-backend.fly.dev/warehouses/warehouse_123" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Updated Warehouse Name",
    "city": "Los Angeles",
    "state": "CA"
  }'
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

ParameterTypeRequiredDescription
idstring✅ YesWarehouse ID

Success Response

Status Code: 200 OK
{
  "id": "warehouse_123",
  "storeId": "store_456",
  "parentId": null,
  "name": "Main Warehouse",
  "email": "[email protected]",
  "isActive": true,
  "isGrouped": false,
  "createdAt": "2024-01-15T10:30:00.000Z",
  "updatedAt": "2024-01-15T10:30:00.000Z"
}

Possible Errors

CodeMessage
403Forbidden - User does not have access to warehouse
404Not Found - Warehouse not found
500Internal Server Error

Example Requests

curl -X DELETE "https://jethings-backend.fly.dev/warehouses/warehouse_123" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN"
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

{
  "statusCode": 403,
  "message": "You do not have access to this store",
  "error": "Forbidden"
}

Common Error Scenarios

403 Forbidden - Store Access
{
  "statusCode": 403,
  "message": "You do not have access to this store"
}
Occurs when the user doesn’t have an active relation with the specified store. 404 Not Found - Warehouse
{
  "statusCode": 404,
  "message": "Warehouse not found"
}
Occurs when the warehouse ID doesn’t exist or doesn’t belong to an accessible store. 400 Bad Request - Validation Error
{
  "statusCode": 400,
  "message": ["name must be a string", "street must be a string"],
  "error": "Bad Request"
}
Occurs when required fields are missing or data types are incorrect.

Usage Examples

Example 1: Create a top-level warehouse

curl -X POST "https://jethings-backend.fly.dev/warehouses" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "x-store-id: store_id_here" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Main Warehouse",
    "street": "123 Industrial Boulevard",
    "city": "New York",
    "state": "NY",
    "country": "United States",
    "postalCode": "10001",
    "email": "[email protected]"
  }'

Example 2: Create a child warehouse

curl -X POST "https://jethings-backend.fly.dev/warehouses" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "x-store-id: store_id_here" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "North Branch",
    "parentId": "warehouse_123",
    "street": "456 North Avenue",
    "city": "Boston",
    "state": "MA",
    "country": "United States",
    "postalCode": "02101",
    "phone": "+1-555-987-6543"
  }'

Example 3: Get warehouses with filtering

curl -X GET "https://jethings-backend.fly.dev/warehouses?parentId=warehouse_123&isActive=true&page=1&limit=20" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "x-store-id: store_id_here"

Example 4: Update warehouse address only

curl -X PUT "https://jethings-backend.fly.dev/warehouses/warehouse_123" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "street": "789 New Street",
    "city": "Philadelphia",
    "state": "PA",
    "postalCode": "19101"
  }'

Example 5: Remove parent relationship

curl -X PUT "https://jethings-backend.fly.dev/warehouses/warehouse_124" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "parentId": null
  }'

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
  • 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

EndpointMethodDescription
/warehousesGETRetrieve paginated list of warehouses
/warehouses/:idGETRetrieve a single warehouse by ID
/warehousesPOSTCreate a new warehouse
/warehouses/:idPUTUpdate an existing warehouse (partial updates)
/warehouses/:idDELETEDelete a warehouse