FastAPI Endpoints¶
Complete reference for all FastAPI REST endpoints in Acumen ERP.
Endpoint Structure¶
All entity endpoints follow this consistent pattern:
/api/{domain}/{entity}/
Example domains: - company - Company and organization management - core - Core system entities - finance - Financial management - hr - Human resources - inventory - Inventory and warehousing - crm - Customer relationship management
Standard CRUD Operations¶
Every entity supports five standard operations:
1. List (GET Collection)¶
GET /api/{domain}/{entity}/
Parameters: - skip (integer, optional): Records to skip (default: 0) - limit (integer, optional): Max records to return (default: 100, max: 100)
Example:
curl http://localhost:8001/api/company/company/?skip=0&limit=25 \
-H "Authorization: Bearer YOUR_TOKEN"
Response:
[
{
"CompanyID": 1,
"CompanyCD": "MAIN",
"CompanyName": "Main Company",
"BaseCuryID": "USD",
"Active": true
},
{
"CompanyID": 2,
"CompanyCD": "BRANCH1",
"CompanyName": "Branch Office",
"BaseCuryID": "USD",
"Active": true
}
]
2. Retrieve (GET Single)¶
GET /api/{domain}/{entity}/{id}
Example:
curl http://localhost:8001/api/company/company/1 \
-H "Authorization: Bearer YOUR_TOKEN"
Response:
{
"CompanyID": 1,
"CompanyCD": "MAIN",
"CompanyName": "Main Company",
"BaseCuryID": "USD",
"Active": true,
"CreatedDate": "2024-01-15T10:30:00",
"ModifiedDate": "2024-01-15T10:30:00"
}
Error (404):
{
"detail": "Company not found"
}
3. Create (POST)¶
POST /api/{domain}/{entity}/
Content-Type: application/json
Example:
curl -X POST http://localhost:8001/api/company/company/ \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"CompanyCD": "NEW",
"CompanyName": "New Company",
"BaseCuryID": "USD",
"Active": true
}'
Response (201):
{
"CompanyID": 3,
"CompanyCD": "NEW",
"CompanyName": "New Company",
"BaseCuryID": "USD",
"Active": true,
"CreatedDate": "2024-01-20T14:25:00",
"ModifiedDate": "2024-01-20T14:25:00"
}
Validation Error (422):
{
"detail": [
{
"loc": ["body", "CompanyCD"],
"msg": "field required",
"type": "value_error.missing"
}
]
}
4. Update (PUT)¶
PUT /api/{domain}/{entity}/{id}
Content-Type: application/json
Example:
curl -X PUT http://localhost:8001/api/company/company/3 \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"CompanyCD": "NEW",
"CompanyName": "Updated Company Name",
"BaseCuryID": "EUR",
"Active": true
}'
Response (200):
{
"CompanyID": 3,
"CompanyCD": "NEW",
"CompanyName": "Updated Company Name",
"BaseCuryID": "EUR",
"Active": true,
"CreatedDate": "2024-01-20T14:25:00",
"ModifiedDate": "2024-01-20T15:10:00"
}
5. Delete (DELETE)¶
DELETE /api/{domain}/{entity}/{id}
Example:
curl -X DELETE http://localhost:8001/api/company/company/3 \
-H "Authorization: Bearer YOUR_TOKEN"
Response (200):
{
"status": "success"
}
Error (404):
{
"detail": "Company not found"
}
Company Domain Endpoints¶
Company¶
GET /api/company/company/ # List companies
GET /api/company/company/{id} # Get company
POST /api/company/company/ # Create company
PUT /api/company/company/{id} # Update company
DELETE /api/company/company/{id} # Delete company
Schema:
{
"CompanyID": 1,
"CompanyCD": "MAIN",
"CompanyName": "Main Company",
"BaseCuryID": "USD",
"Active": true,
"CreatedDate": "2024-01-15T10:30:00",
"ModifiedDate": "2024-01-15T10:30:00"
}
Organization¶
GET /api/company/organization/ # List organizations
GET /api/company/organization/{id} # Get organization
POST /api/company/organization/ # Create organization
PUT /api/company/organization/{id} # Update organization
DELETE /api/company/organization/{id} # Delete organization
Schema:
{
"OrganizationID": 1,
"OrganizationCD": "HQ",
"OrganizationName": "Headquarters",
"CompanyID": 1,
"Active": true
}
Core Domain Endpoints¶
Account¶
GET /api/core/account/ # List accounts
GET /api/core/account/{id} # Get account
POST /api/core/account/ # Create account
PUT /api/core/account/{id} # Update account
DELETE /api/core/account/{id} # Delete account
Schema:
{
"AccountID": 1,
"AccountCD": "1000",
"AccountName": "Cash",
"AccountClassID": 1,
"Active": true,
"CuryID": "USD"
}
Address¶
GET /api/core/address/ # List addresses
GET /api/core/address/{id} # Get address
POST /api/core/address/ # Create address
PUT /api/core/address/{id} # Update address
DELETE /api/core/address/{id} # Delete address
Schema:
{
"AddressID": 1,
"AddressLine1": "123 Main St",
"AddressLine2": "Suite 100",
"City": "New York",
"State": "NY",
"PostalCode": "10001",
"Country": "USA"
}
Currency¶
GET /api/core/currency/ # List currencies
GET /api/core/currency/{id} # Get currency
POST /api/core/currency/ # Create currency
PUT /api/core/currency/{id} # Update currency
DELETE /api/core/currency/{id} # Delete currency
Schema:
{
"CuryID": "USD",
"CuryName": "US Dollar",
"CurySymbol": "$",
"DecimalPlaces": 2,
"Active": true
}
Finance Domain Endpoints¶
Invoice (Example)¶
GET /api/finance/invoice/ # List invoices
GET /api/finance/invoice/{id} # Get invoice
POST /api/finance/invoice/ # Create invoice
PUT /api/finance/invoice/{id} # Update invoice
DELETE /api/finance/invoice/{id} # Delete invoice
Schema Example:
{
"InvoiceID": 1,
"InvoiceNbr": "INV-001",
"InvoiceDate": "2024-01-20",
"CustomerID": 123,
"TotalAmount": 1500.00,
"CuryID": "USD",
"Status": "Pending"
}
Router Modes¶
Acumen FastAPI supports three router modes for performance optimization:
Minimal Mode¶
export ROUTER_MODE=minimal
python run.py
Loads: - Essential projection endpoints - Core system entities
Startup time: ~2-3 seconds Use case: Development, testing
Core Mode (Default)¶
export ROUTER_MODE=core
python run.py
Loads: - Core domain (685+ entities) - Finance domain (452+ entities) - Company domain (8 entities)
Startup time: ~5-10 seconds Use case: Standard development
Full Mode¶
export ROUTER_MODE=full
python run.py
Loads: - All 2016+ entities across all domains
Startup time: ~30+ seconds Use case: Production, full testing
Pagination¶
All list endpoints support pagination:
GET /api/company/company/?skip=0&limit=25
Parameters: - skip: Number of records to skip (offset) - limit: Maximum records to return (max: 100)
Example:
// Page 1 (records 0-24)
GET /api/company/company/?skip=0&limit=25
// Page 2 (records 25-49)
GET /api/company/company/?skip=25&limit=25
// Page 3 (records 50-74)
GET /api/company/company/?skip=50&limit=25
Error Handling¶
Common Errors¶
401 Unauthorized
{
"detail": "Not authenticated"
}
Solution: Include valid JWT token in Authorization header
403 Forbidden
{
"detail": "Not enough permissions"
}
Solution: User lacks required permissions for this action
404 Not Found
{
"detail": "Company not found"
}
Solution: Record with given ID doesn't exist
422 Validation Error
{
"detail": [
{
"loc": ["body", "CompanyCD"],
"msg": "field required",
"type": "value_error.missing"
},
{
"loc": ["body", "BaseCuryID"],
"msg": "string does not match regex \"^[A-Z]{3}$\"",
"type": "value_error.str.regex",
"ctx": {"pattern": "^[A-Z]{3}$"}
}
]
}
Solution: Fix validation errors in request body
500 Internal Server Error
{
"detail": "Internal server error"
}
Solution: Check server logs, report to development team
Best Practices¶
1. Use Pagination¶
// ✅ Good - Paginated requests
async function getAllCompanies() {
const pageSize = 100;
let skip = 0;
let allCompanies = [];
let hasMore = true;
while (hasMore) {
const response = await api.get(`/api/company/company/?skip=${skip}&limit=${pageSize}`);
const companies = response.data;
allCompanies = [...allCompanies, ...companies];
skip += pageSize;
hasMore = companies.length === pageSize;
}
return allCompanies;
}
// ❌ Bad - No pagination
const companies = await api.get('/api/company/company/');
2. Handle Errors¶
// ✅ Good - Error handling
try {
const response = await api.get('/api/company/company/123');
return response.data;
} catch (error) {
if (error.response?.status === 404) {
console.error('Company not found');
} else if (error.response?.status === 401) {
console.error('Not authenticated');
// Redirect to login
} else {
console.error('Unexpected error:', error);
}
throw error;
}
3. Validate Before Sending¶
// ✅ Good - Validate before API call
function validateCompany(data) {
const errors = [];
if (!data.CompanyCD) {
errors.push('Company code is required');
}
if (!/^[A-Z0-9]+$/.test(data.CompanyCD)) {
errors.push('Company code must be uppercase alphanumeric');
}
if (!data.CompanyName) {
errors.push('Company name is required');
}
return errors;
}
const errors = validateCompany(formData);
if (errors.length > 0) {
// Show validation errors to user
return;
}
// Only call API if validation passes
await api.post('/api/company/company/', formData);
4. Use Proper HTTP Methods¶
// ✅ Good - Correct methods
GET - Reading data (no side effects)
POST - Creating new records
PUT - Updating existing records (full replacement)
PATCH - Partial updates (future)
DELETE - Removing records
// ❌ Bad
POST - For reading data
GET - For modifying data
5. Cache When Appropriate¶
// ✅ Good - Cache static/slow-changing data
const currencyCache = new Map();
async function getCurrency(curyId) {
if (currencyCache.has(curyId)) {
return currencyCache.get(curyId);
}
const response = await api.get(`/api/core/currency/${curyId}`);
currencyCache.set(curyId, response.data);
return response.data;
}
Testing Endpoints¶
Using Swagger UI¶
- Navigate to http://localhost:8001/docs
- Click "Authorize" and enter your JWT token
- Select an endpoint to test
- Click "Try it out"
- Fill in parameters
- Click "Execute"
- View response
Using curl¶
# Store token in variable
TOKEN="your_jwt_token_here"
# List companies
curl http://localhost:8001/api/company/company/ \
-H "Authorization: Bearer $TOKEN"
# Get specific company
curl http://localhost:8001/api/company/company/1 \
-H "Authorization: Bearer $TOKEN"
# Create company
curl -X POST http://localhost:8001/api/company/company/ \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"CompanyCD": "TEST", "CompanyName": "Test Co", "BaseCuryID": "USD"}'
Using Python¶
import requests
BASE_URL = "http://localhost:8001"
TOKEN = "your_jwt_token"
headers = {
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json"
}
# List companies
response = requests.get(f"{BASE_URL}/api/company/company/", headers=headers)
companies = response.json()
print(f"Found {len(companies)} companies")
# Create company
new_company = {
"CompanyCD": "TEST",
"CompanyName": "Test Company",
"BaseCuryID": "USD",
"Active": True
}
response = requests.post(
f"{BASE_URL}/api/company/company/",
json=new_company,
headers=headers
)
if response.status_code == 201:
created = response.json()
print(f"Created company with ID: {created['CompanyID']}")
else:
print(f"Error: {response.json()}")
Next Steps¶
- API Reference Index - Overview and authentication
- Authentication Guide - Detailed auth documentation
- Integration Examples - Real-world usage
- YAML Configuration - Connect YAML to APIs