API Authentication
Learn how to authenticate your API requests to access the Inventory Service endpoints.
API Key Authentication
The Inventory Service uses API key authentication via middleware. All requests must include a valid API key to access protected endpoints.
Authentication Method
The service uses the ApiKeyMiddleware to validate incoming requests. All API routes are protected by this middleware.
Required Headers
| Header | Value | Description |
|---|---|---|
| Content-Type | application/json | Indicates that the request body is JSON |
| X-API-Key | {your-api-key} | Your API key for authentication |
MS Trace Requirement
All API requests must include MS trace information for request tracking and monitoring across the microservices ecosystem.
MS Trace Structure
{
"ms_trace": [
{
"ms_signature": "inventory-service-req-123456",
"warning_count": 0
}
]
}
| Field | Type | Required | Description |
|---|---|---|---|
| ms_trace | array | Required | Array of trace objects for request tracking |
| ms_signature | string | Required | Unique signature for request identification |
| warning_count | integer | Required | Number of warnings in the request chain |
Example Request
Here's an example of how to structure your API requests to the Inventory Service:
curl -X POST https://your-domain.com/api/warehouses/create-warehouse \
-H "Content-Type: application/json" \
-H "X-API-Key: your-api-key-here" \
-d '{
"ms_trace": [
{
"ms_signature": "inventory-req-" + Date.now(),
"warning_count": 0
}
],
"data": {
"name": "Main Warehouse",
"type": "INTERNAL",
"partner_id": 123,
"description": "Primary storage facility"
}
}'
Error Responses
If authentication fails, you'll receive one of these error responses:
Authentication Errors
Error responses may be returned for authentication failures or missing required trace information. Exact error formats not verified from middleware code.
Global Request Tracer
The service implements a Global Request Tracer for monitoring and tracking requests across the system. This helps in debugging and performance monitoring.
Controller Usage
All controllers automatically set the current trace using:
$this->setCurrentTrace($request->validated()['ms_trace']);