API Conventions
This page describes the patterns and conventions used consistently across all Moon ERP API endpoints.
Content Type
All requests and responses use JSON. Include these headers on every request:
Content-Type: application/json
Accept: application/jsonURL Structure
All API endpoints follow this pattern:
/api/{module}/{resource}Examples:
| Method | URL | Description |
|---|---|---|
GET | /api/core/branches | List all branches |
POST | /api/core/branches | Create a branch |
GET | /api/core/branches/5 | Get branch by ID |
PUT | /api/core/branches/5 | Update a branch |
DELETE | /api/core/branches/5 | Delete a branch |
GET | /api/accounting/accounts | List accounts |
POST | /api/accounting/journal-entries | Create a journal entry |
ID Fields
All resources use integer auto-incrementing primary keys. IDs are always returned as integers in JSON responses.
Pagination
List endpoints return paginated results using Laravel's standard pagination format. Control pagination with query parameters:
| Parameter | Default | Description |
|---|---|---|
page | 1 | Page number |
per_page | 15 | Number of items per page |
Example Request
GET /api/core/users?page=2&per_page=10Paginated Response Structure
{
"data": [
{ "id": 11, "name": "User 11", "email": "user11@example.com" },
{ "id": 12, "name": "User 12", "email": "user12@example.com" }
],
"links": {
"first": "https://moon-erp.test/api/core/users?page=1",
"last": "https://moon-erp.test/api/core/users?page=5",
"prev": "https://moon-erp.test/api/core/users?page=1",
"next": "https://moon-erp.test/api/core/users?page=3"
},
"meta": {
"current_page": 2,
"from": 11,
"last_page": 5,
"per_page": 10,
"to": 20,
"total": 50
}
}Single-resource endpoints (GET /api/.../resource/{id}, POST, PUT) return the resource directly inside a data wrapper:
{
"data": {
"id": 1,
"name": "Main Branch"
}
}Localization
Moon ERP supports Arabic and English. The API defaults to Arabic.
Set the Accept-Language header to control the language of localized fields:
| Header Value | Effect |
|---|---|
Accept-Language: ar | Arabic names and messages (default) |
Accept-Language: en | English names and messages |
Localized models expose all variants:
{
"data": {
"id": 1,
"name": "المقر الرئيسي",
"name_en": "Headquarters",
"name_ar": "المقر الرئيسي"
}
}The name field reflects the locale requested via the header. The name_en and name_ar fields are always present so the client can display both if needed.
Date and Time Format
All date and time fields use ISO 8601 format with UTC timezone:
2026-02-16T10:30:00.000000ZWhen sending dates in request bodies, use the same ISO 8601 format or YYYY-MM-DD for date-only fields.
Monetary Fields
Moon ERP supports multiple currencies with varying decimal precision:
| Currency | Code | Decimals | Example |
|---|---|---|---|
| Kuwaiti Dinar | KWD | 3 | 1234.567 |
| Egyptian Pound | EGP | 2 | 1234.56 |
All monetary fields in the database use decimal(12, 3) to accommodate KWD's three decimal places. API responses return monetary values as numbers (not strings):
{
"amount": 1234.567,
"currency_code": "KWD"
}Soft Deletes
All resources use soft deletes. When you send a DELETE request, the record is marked as deleted but remains in the database. Soft-deleted records are excluded from list endpoints by default.
A successful delete returns:
{
"message": "Deleted"
}Boolean Fields
Boolean fields use true/false in both requests and responses. Common boolean fields include:
| Field | Description |
|---|---|
is_active | Whether the resource is active |
is_default | Whether this is the default option |
is_posted | Whether a journal entry is posted |
allow_manual | Whether manual journal entries are allowed |
In request bodies, send booleans as JSON true/false (not 1/0 or "true"/"false"):
{
"is_active": true,
"is_default": false
}Filtering and Sorting
Many list endpoints support query parameters for filtering and sorting. Check individual endpoint documentation for supported parameters. Common patterns include:
GET /api/accounting/accounts?type=asset&is_active=true
GET /api/core/users?search=ahmedHTTP Methods Summary
| Method | Usage | Typical Status Code |
|---|---|---|
GET | Retrieve resource(s) | 200 OK |
POST | Create a new resource | 201 Created |
PUT | Update an existing resource | 200 OK |
DELETE | Soft-delete a resource | 200 OK |