Skip to main content

Overview

The Locations API enables management of hierarchical location structures within containers. Locations can be nested to create organizational hierarchies, allowing for precise tracking of where inventory items are stored.

Endpoints

Get Locations

Retrieves all locations associated with a specific container.

Path Parameters

integer
required
The ID of the container whose locations to retrieve

Response

Location[]
Array of location objects

Example Request

Example Response

Error Responses

error
Unauthorized - Authentication required or token invalid
error
Container not found

Create Location

Creates a new location within a container.

Request Body

integer
required
ID of the container to create the location in
string
required
Name of the location
string
Optional description of the location
integer
ID of the parent location (omit for root-level location)

Response

Location
The newly created location object

Example Request

Example Response

Error Responses

success
Location created successfully
error
Unauthorized - Invalid or missing authentication token
error
Bad request - Invalid parent_id or missing required fields

Update Location

Updates an existing location’s details.

Path Parameters

integer
required
The ID of the location to update

Request Body

string
required
Updated name of the location
string
Updated description
integer
Updated parent location ID (use null to make it a root location)

Response

Location
The updated location object

Example Request

Example Response

Error Responses

success
Location updated successfully
error
Unauthorized - Authentication required
error
Location not found
error
Bad request - Invalid parent_id (would create circular hierarchy)

Delete Location

Deletes a location from the system.

Path Parameters

integer
required
The ID of the location to delete

Response

Returns status code 204 (No Content) or 200 (OK) on successful deletion.

Example Request

Error Responses

success
Location deleted successfully (no content returned)
success
Location deleted successfully
error
Unauthorized - Authentication required
error
Location not found
error
Conflict - Cannot delete location with child locations or assigned items

Business Logic Notes

Hierarchical Structure

  • Locations support unlimited nesting depth through the parent_id field
  • The children array is populated recursively when retrieving locations
  • Root-level locations have parent_id set to null

Deletion Rules

  • Locations with child locations must have children removed first
  • Locations with assigned inventory items cannot be deleted until items are reassigned
  • Consider implementing soft deletes for audit trail purposes

Performance Considerations

  • The children array is not included in toJson() to prevent circular serialization issues
  • For deep hierarchies, consider implementing pagination or lazy loading of child locations
  • The getLocationsCount() method fetches all locations and returns the count - consider server-side counting for large datasets

Access Control

  • All location operations require valid JWT authentication
  • Users can only access locations within containers they have permission to view
  • Container ownership determines location management permissions